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 
48 typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
49 typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
50 typedef struct _xf86Lease xf86LeaseRec, *xf86LeasePtr;
51 
52 /* define a standard for connector types */
53 typedef 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 
68 typedef enum _xf86OutputStatus {
69     XF86OutputStatusConnected,
70     XF86OutputStatusDisconnected,
71     XF86OutputStatusUnknown
72 } xf86OutputStatus;
73 
74 typedef enum _xf86DriverTransforms {
75     XF86DriverTransformNone = 0,
76     XF86DriverTransformOutput = 1 << 0,
77     XF86DriverTransformCursorImage = 1 << 1,
78     XF86DriverTransformCursorPosition = 1 << 2,
79 } xf86DriverTransforms;
80 
81 
82 struct 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 
93 typedef 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 
253 struct _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 
417 typedef 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 
536 struct _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 
658 typedef 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 
683 struct _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 
729 typedef 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  */
761 extern _X_EXPORT void
762 xf86CrtcLeaseTerminated(RRLeasePtr lease);
763 
764 extern _X_EXPORT void
765 xf86CrtcLeaseStarted(RRLeasePtr lease);
766 
767 typedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen);
768 
769 typedef 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 
833 extern _X_EXPORT int xf86CrtcConfigPrivateIndex;
834 
835 #define XF86_CRTC_CONFIG_PTR(p)	((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
836 
837 static _X_INLINE xf86OutputPtr
xf86CompatOutput(ScrnInfoPtr pScrn)838 xf86CompatOutput(ScrnInfoPtr pScrn)
839 {
840     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
841 
842     if (config->compat_output < 0)
843         return NULL;
844     return config->output[config->compat_output];
845 }
846 
847 static _X_INLINE xf86CrtcPtr
xf86CompatCrtc(ScrnInfoPtr pScrn)848 xf86CompatCrtc(ScrnInfoPtr pScrn)
849 {
850     xf86OutputPtr compat_output = xf86CompatOutput(pScrn);
851 
852     if (!compat_output)
853         return NULL;
854     return compat_output->crtc;
855 }
856 
857 static _X_INLINE RRCrtcPtr
xf86CompatRRCrtc(ScrnInfoPtr pScrn)858 xf86CompatRRCrtc(ScrnInfoPtr pScrn)
859 {
860     xf86CrtcPtr compat_crtc = xf86CompatCrtc(pScrn);
861 
862     if (!compat_crtc)
863         return NULL;
864     return compat_crtc->randr_crtc;
865 }
866 
867 /*
868  * Initialize xf86CrtcConfig structure
869  */
870 
871 extern _X_EXPORT void
872  xf86CrtcConfigInit(ScrnInfoPtr scrn, const xf86CrtcConfigFuncsRec * funcs);
873 
874 extern _X_EXPORT void
875 
876 xf86CrtcSetSizeRange(ScrnInfoPtr scrn,
877                      int minWidth, int minHeight, int maxWidth, int maxHeight);
878 
879 /*
880  * Crtc functions
881  */
882 extern _X_EXPORT xf86CrtcPtr
883 xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs);
884 
885 extern _X_EXPORT void
886  xf86CrtcDestroy(xf86CrtcPtr crtc);
887 
888 /**
889  * Sets the given video mode on the given crtc
890  */
891 
892 extern _X_EXPORT Bool
893 
894 xf86CrtcSetModeTransform(xf86CrtcPtr crtc, DisplayModePtr mode,
895                          Rotation rotation, RRTransformPtr transform, int x,
896                          int y);
897 
898 extern _X_EXPORT Bool
899 
900 xf86CrtcSetMode(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
901                 int x, int y);
902 
903 extern _X_EXPORT void
904  xf86CrtcSetOrigin(xf86CrtcPtr crtc, int x, int y);
905 
906 /*
907  * Assign crtc rotation during mode set
908  */
909 extern _X_EXPORT Bool
910  xf86CrtcRotate(xf86CrtcPtr crtc);
911 
912 /*
913  * Clean up any rotation data, used when a crtc is turned off
914  * as well as when rotation is disabled.
915  */
916 extern _X_EXPORT void
917  xf86RotateDestroy(xf86CrtcPtr crtc);
918 
919 /*
920  * free shadow memory allocated for all crtcs
921  */
922 extern _X_EXPORT void
923  xf86RotateFreeShadow(ScrnInfoPtr pScrn);
924 
925 /*
926  * Clean up rotation during CloseScreen
927  */
928 extern _X_EXPORT void
929  xf86RotateCloseScreen(ScreenPtr pScreen);
930 
931 /**
932  * Return whether any output is assigned to the crtc
933  */
934 extern _X_EXPORT Bool
935  xf86CrtcInUse(xf86CrtcPtr crtc);
936 
937 /*
938  * Output functions
939  */
940 extern _X_EXPORT xf86OutputPtr
941 xf86OutputCreate(ScrnInfoPtr scrn,
942                  const xf86OutputFuncsRec * funcs, const char *name);
943 
944 extern _X_EXPORT void
945  xf86OutputUseScreenMonitor(xf86OutputPtr output, Bool use_screen_monitor);
946 
947 extern _X_EXPORT Bool
948  xf86OutputRename(xf86OutputPtr output, const char *name);
949 
950 extern _X_EXPORT void
951  xf86OutputDestroy(xf86OutputPtr output);
952 
953 extern _X_EXPORT void
954  xf86ProbeOutputModes(ScrnInfoPtr pScrn, int maxX, int maxY);
955 
956 extern _X_EXPORT void
957  xf86SetScrnInfoModes(ScrnInfoPtr pScrn);
958 
959 #ifdef RANDR_13_INTERFACE
960 #define ScreenInitRetType	int
961 #else
962 #define ScreenInitRetType	Bool
963 #endif
964 
965 extern _X_EXPORT ScreenInitRetType xf86CrtcScreenInit(ScreenPtr pScreen);
966 
967 extern _X_EXPORT Bool
968  xf86InitialConfiguration(ScrnInfoPtr pScrn, Bool canGrow);
969 
970 extern _X_EXPORT void
971  xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
972 
973 extern _X_EXPORT Bool
974  xf86SaveScreen(ScreenPtr pScreen, int mode);
975 
976 extern _X_EXPORT void
977  xf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
978 
979 extern _X_EXPORT DisplayModePtr
980 xf86OutputFindClosestMode(xf86OutputPtr output, DisplayModePtr desired);
981 
982 extern _X_EXPORT Bool
983 
984 xf86SetSingleMode(ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation);
985 
986 /**
987  * Set the EDID information for the specified output
988  */
989 extern _X_EXPORT void
990  xf86OutputSetEDID(xf86OutputPtr output, xf86MonPtr edid_mon);
991 
992 /**
993  * Set the TILE information for the specified output
994  */
995 extern _X_EXPORT void
996 xf86OutputSetTile(xf86OutputPtr output, struct xf86CrtcTileInfo *tile_info);
997 
998 extern _X_EXPORT Bool
999 xf86OutputParseKMSTile(const char *tile_data, int tile_length, struct xf86CrtcTileInfo *tile_info);
1000 
1001 /**
1002  * Return the list of modes supported by the EDID information
1003  * stored in 'output'
1004  */
1005 extern _X_EXPORT DisplayModePtr xf86OutputGetEDIDModes(xf86OutputPtr output);
1006 
1007 extern _X_EXPORT xf86MonPtr
1008 xf86OutputGetEDID(xf86OutputPtr output, I2CBusPtr pDDCBus);
1009 
1010 /**
1011  * Initialize dga for this screen
1012  */
1013 
1014 #ifdef XFreeXDGA
1015 extern _X_EXPORT Bool
1016  xf86DiDGAInit(ScreenPtr pScreen, unsigned long dga_address);
1017 
1018 /* this is the real function, used only internally */
1019 _X_INTERNAL Bool
1020  _xf86_di_dga_init_internal(ScreenPtr pScreen);
1021 
1022 /**
1023  * Re-initialize dga for this screen (as when the set of modes changes)
1024  */
1025 
1026 extern _X_EXPORT Bool
1027  xf86DiDGAReInit(ScreenPtr pScreen);
1028 #endif
1029 
1030 /* This is the real function, used only internally */
1031 _X_INTERNAL Bool
1032  _xf86_di_dga_reinit_internal(ScreenPtr pScreen);
1033 
1034 /*
1035  * Set the subpixel order reported for the screen using
1036  * the information from the outputs
1037  */
1038 
1039 extern _X_EXPORT void
1040  xf86CrtcSetScreenSubpixelOrder(ScreenPtr pScreen);
1041 
1042 /*
1043  * Get a standard string name for a connector type
1044  */
1045 extern _X_EXPORT const char *xf86ConnectorGetName(xf86ConnectorType connector);
1046 
1047 /*
1048  * Using the desired mode information in each crtc, set
1049  * modes (used in EnterVT functions, or at server startup)
1050  */
1051 
1052 extern _X_EXPORT Bool
1053  xf86SetDesiredModes(ScrnInfoPtr pScrn);
1054 
1055 /**
1056  * Initialize the CRTC-based cursor code. CRTC function vectors must
1057  * contain relevant cursor setting functions.
1058  *
1059  * Driver should call this from ScreenInit function
1060  */
1061 extern _X_EXPORT Bool
1062  xf86_cursors_init(ScreenPtr screen, int max_width, int max_height, int flags);
1063 
1064 /**
1065  * Superseeded by xf86CursorResetCursor, which is getting called
1066  * automatically when necessary.
1067  */
xf86_reload_cursors(ScreenPtr screen)1068 static _X_INLINE _X_DEPRECATED void xf86_reload_cursors(ScreenPtr screen) {}
1069 
1070 /**
1071  * Called from EnterVT to turn the cursors back on
1072  */
1073 extern _X_EXPORT Bool
1074  xf86_show_cursors(ScrnInfoPtr scrn);
1075 
1076 /**
1077  * Called by the driver to turn a single crtc's cursor off
1078  */
1079 extern _X_EXPORT void
1080 xf86_crtc_hide_cursor(xf86CrtcPtr crtc);
1081 
1082 /**
1083  * Called by the driver to turn a single crtc's cursor on
1084  */
1085 extern _X_EXPORT Bool
1086 xf86_crtc_show_cursor(xf86CrtcPtr crtc);
1087 
1088 /**
1089  * Called by the driver to turn cursors off
1090  */
1091 extern _X_EXPORT void
1092  xf86_hide_cursors(ScrnInfoPtr scrn);
1093 
1094 /**
1095  * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
1096  */
1097 extern _X_EXPORT void
1098  xf86_cursors_fini(ScreenPtr screen);
1099 
1100 #ifdef XV
1101 /*
1102  * For overlay video, compute the relevant CRTC and
1103  * clip video to that.
1104  * wraps xf86XVClipVideoHelper()
1105  */
1106 
1107 extern _X_EXPORT Bool
1108 
1109 xf86_crtc_clip_video_helper(ScrnInfoPtr pScrn,
1110                             xf86CrtcPtr * crtc_ret,
1111                             xf86CrtcPtr desired_crtc,
1112                             BoxPtr dst,
1113                             INT32 *xa,
1114                             INT32 *xb,
1115                             INT32 *ya,
1116                             INT32 *yb,
1117                             RegionPtr reg, INT32 width, INT32 height);
1118 #endif
1119 
1120 extern _X_EXPORT xf86_crtc_notify_proc_ptr
1121 xf86_wrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr new);
1122 
1123 extern _X_EXPORT void
1124  xf86_unwrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr old);
1125 
1126 extern _X_EXPORT void
1127  xf86_crtc_notify(ScreenPtr pScreen);
1128 
1129 /**
1130  * Gamma
1131  */
1132 
1133 extern _X_EXPORT Bool
1134  xf86_crtc_supports_gamma(ScrnInfoPtr pScrn);
1135 
1136 extern _X_EXPORT void
1137 xf86ProviderSetup(ScrnInfoPtr scrn,
1138                   const xf86ProviderFuncsRec * funcs, const char *name);
1139 
1140 extern _X_EXPORT void
1141 xf86DetachAllCrtc(ScrnInfoPtr scrn);
1142 
1143 #endif                          /* _XF86CRTC_H_ */
1144