1706f2543Smrg/*
2706f2543Smrg * Copyright © 2006 Keith Packard
3706f2543Smrg *
4706f2543Smrg * Permission to use, copy, modify, distribute, and sell this software and its
5706f2543Smrg * documentation for any purpose is hereby granted without fee, provided that
6706f2543Smrg * the above copyright notice appear in all copies and that both that copyright
7706f2543Smrg * notice and this permission notice appear in supporting documentation, and
8706f2543Smrg * that the name of the copyright holders not be used in advertising or
9706f2543Smrg * publicity pertaining to distribution of the software without specific,
10706f2543Smrg * written prior permission.  The copyright holders make no representations
11706f2543Smrg * about the suitability of this software for any purpose.  It is provided "as
12706f2543Smrg * is" without express or implied warranty.
13706f2543Smrg *
14706f2543Smrg * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15706f2543Smrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16706f2543Smrg * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17706f2543Smrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18706f2543Smrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19706f2543Smrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20706f2543Smrg * OF THIS SOFTWARE.
21706f2543Smrg */
22706f2543Smrg#ifndef _XF86CRTC_H_
23706f2543Smrg#define _XF86CRTC_H_
24706f2543Smrg
25706f2543Smrg#include <edid.h>
26706f2543Smrg#include "randrstr.h"
27706f2543Smrg#if XF86_MODES_RENAME
28706f2543Smrg#include "xf86Rename.h"
29706f2543Smrg#endif
30706f2543Smrg#include "xf86Modes.h"
31706f2543Smrg#include "xf86Cursor.h"
32706f2543Smrg#include "xf86i2c.h"
33706f2543Smrg#include "damage.h"
34706f2543Smrg#include "picturestr.h"
35706f2543Smrg
36706f2543Smrg/* Compat definitions for older X Servers. */
37706f2543Smrg#ifndef M_T_PREFERRED
38706f2543Smrg#define M_T_PREFERRED	0x08
39706f2543Smrg#endif
40706f2543Smrg#ifndef M_T_DRIVER
41706f2543Smrg#define M_T_DRIVER	0x40
42706f2543Smrg#endif
43706f2543Smrg#ifndef M_T_USERPREF
44706f2543Smrg#define M_T_USERPREF	0x80
45706f2543Smrg#endif
46706f2543Smrg#ifndef HARDWARE_CURSOR_ARGB
47706f2543Smrg#define HARDWARE_CURSOR_ARGB				0x00004000
48706f2543Smrg#endif
49706f2543Smrg
50706f2543Smrgtypedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr;
51706f2543Smrgtypedef struct _xf86Output xf86OutputRec, *xf86OutputPtr;
52706f2543Smrg
53706f2543Smrg/* define a standard for connector types */
54706f2543Smrgtypedef enum _xf86ConnectorType {
55706f2543Smrg   XF86ConnectorNone,
56706f2543Smrg   XF86ConnectorVGA,
57706f2543Smrg   XF86ConnectorDVI_I,
58706f2543Smrg   XF86ConnectorDVI_D,
59706f2543Smrg   XF86ConnectorDVI_A,
60706f2543Smrg   XF86ConnectorComposite,
61706f2543Smrg   XF86ConnectorSvideo,
62706f2543Smrg   XF86ConnectorComponent,
63706f2543Smrg   XF86ConnectorLFP,
64706f2543Smrg   XF86ConnectorProprietary,
65706f2543Smrg   XF86ConnectorHDMI,
66706f2543Smrg   XF86ConnectorDisplayPort,
67706f2543Smrg} xf86ConnectorType;
68706f2543Smrg
69706f2543Smrgtypedef enum _xf86OutputStatus {
70706f2543Smrg   XF86OutputStatusConnected,
71706f2543Smrg   XF86OutputStatusDisconnected,
72706f2543Smrg   XF86OutputStatusUnknown
73706f2543Smrg} xf86OutputStatus;
74706f2543Smrg
75706f2543Smrgtypedef struct _xf86CrtcFuncs {
76706f2543Smrg   /**
77706f2543Smrg    * Turns the crtc on/off, or sets intermediate power levels if available.
78706f2543Smrg    *
79706f2543Smrg    * Unsupported intermediate modes drop to the lower power setting.  If the
80706f2543Smrg    * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to
81706f2543Smrg    * be safe to call mode_set.
82706f2543Smrg    */
83706f2543Smrg   void
84706f2543Smrg    (*dpms)(xf86CrtcPtr		crtc,
85706f2543Smrg	    int		    	mode);
86706f2543Smrg
87706f2543Smrg   /**
88706f2543Smrg    * Saves the crtc's state for restoration on VT switch.
89706f2543Smrg    */
90706f2543Smrg   void
91706f2543Smrg    (*save)(xf86CrtcPtr		crtc);
92706f2543Smrg
93706f2543Smrg   /**
94706f2543Smrg    * Restore's the crtc's state at VT switch.
95706f2543Smrg    */
96706f2543Smrg   void
97706f2543Smrg    (*restore)(xf86CrtcPtr	crtc);
98706f2543Smrg
99706f2543Smrg    /**
100706f2543Smrg     * Lock CRTC prior to mode setting, mostly for DRI.
101706f2543Smrg     * Returns whether unlock is needed
102706f2543Smrg     */
103706f2543Smrg    Bool
104706f2543Smrg    (*lock) (xf86CrtcPtr crtc);
105706f2543Smrg
106706f2543Smrg    /**
107706f2543Smrg     * Unlock CRTC after mode setting, mostly for DRI
108706f2543Smrg     */
109706f2543Smrg    void
110706f2543Smrg    (*unlock) (xf86CrtcPtr crtc);
111706f2543Smrg
112706f2543Smrg    /**
113706f2543Smrg     * Callback to adjust the mode to be set in the CRTC.
114706f2543Smrg     *
115706f2543Smrg     * This allows a CRTC to adjust the clock or even the entire set of
116706f2543Smrg     * timings, which is used for panels with fixed timings or for
117706f2543Smrg     * buses with clock limitations.
118706f2543Smrg     */
119706f2543Smrg    Bool
120706f2543Smrg    (*mode_fixup)(xf86CrtcPtr crtc,
121706f2543Smrg		  DisplayModePtr mode,
122706f2543Smrg		  DisplayModePtr adjusted_mode);
123706f2543Smrg
124706f2543Smrg    /**
125706f2543Smrg     * Prepare CRTC for an upcoming mode set.
126706f2543Smrg     */
127706f2543Smrg    void
128706f2543Smrg    (*prepare)(xf86CrtcPtr crtc);
129706f2543Smrg
130706f2543Smrg    /**
131706f2543Smrg     * Callback for setting up a video mode after fixups have been made.
132706f2543Smrg     */
133706f2543Smrg    void
134706f2543Smrg    (*mode_set)(xf86CrtcPtr crtc,
135706f2543Smrg		DisplayModePtr mode,
136706f2543Smrg		DisplayModePtr adjusted_mode,
137706f2543Smrg		int x, int y);
138706f2543Smrg
139706f2543Smrg    /**
140706f2543Smrg     * Commit mode changes to a CRTC
141706f2543Smrg     */
142706f2543Smrg    void
143706f2543Smrg    (*commit)(xf86CrtcPtr crtc);
144706f2543Smrg
145706f2543Smrg    /* Set the color ramps for the CRTC to the given values. */
146706f2543Smrg    void
147706f2543Smrg    (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue,
148706f2543Smrg		 int size);
149706f2543Smrg
150706f2543Smrg    /**
151706f2543Smrg     * Allocate the shadow area, delay the pixmap creation until needed
152706f2543Smrg     */
153706f2543Smrg    void *
154706f2543Smrg    (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height);
155706f2543Smrg
156706f2543Smrg    /**
157706f2543Smrg     * Create shadow pixmap for rotation support
158706f2543Smrg     */
159706f2543Smrg    PixmapPtr
160706f2543Smrg    (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height);
161706f2543Smrg
162706f2543Smrg    /**
163706f2543Smrg     * Destroy shadow pixmap
164706f2543Smrg     */
165706f2543Smrg    void
166706f2543Smrg    (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data);
167706f2543Smrg
168706f2543Smrg    /**
169706f2543Smrg     * Set cursor colors
170706f2543Smrg     */
171706f2543Smrg    void
172706f2543Smrg    (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg);
173706f2543Smrg
174706f2543Smrg    /**
175706f2543Smrg     * Set cursor position
176706f2543Smrg     */
177706f2543Smrg    void
178706f2543Smrg    (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y);
179706f2543Smrg
180706f2543Smrg    /**
181706f2543Smrg     * Show cursor
182706f2543Smrg     */
183706f2543Smrg    void
184706f2543Smrg    (*show_cursor) (xf86CrtcPtr crtc);
185706f2543Smrg
186706f2543Smrg    /**
187706f2543Smrg     * Hide cursor
188706f2543Smrg     */
189706f2543Smrg    void
190706f2543Smrg    (*hide_cursor) (xf86CrtcPtr crtc);
191706f2543Smrg
192706f2543Smrg    /**
193706f2543Smrg     * Load monochrome image
194706f2543Smrg     */
195706f2543Smrg    void
196706f2543Smrg    (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image);
197706f2543Smrg
198706f2543Smrg    /**
199706f2543Smrg     * Load ARGB image
200706f2543Smrg     */
201706f2543Smrg     void
202706f2543Smrg     (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image);
203706f2543Smrg
204706f2543Smrg    /**
205706f2543Smrg     * Clean up driver-specific bits of the crtc
206706f2543Smrg     */
207706f2543Smrg    void
208706f2543Smrg    (*destroy) (xf86CrtcPtr	crtc);
209706f2543Smrg
210706f2543Smrg    /**
211706f2543Smrg     * Less fine-grained mode setting entry point for kernel modesetting
212706f2543Smrg     */
213706f2543Smrg    Bool
214706f2543Smrg    (*set_mode_major)(xf86CrtcPtr crtc, DisplayModePtr mode,
215706f2543Smrg		      Rotation rotation, int x, int y);
216706f2543Smrg
217706f2543Smrg    /**
218706f2543Smrg     * Callback for panning. Doesn't change the mode.
219706f2543Smrg     * Added in ABI version 2
220706f2543Smrg     */
221706f2543Smrg    void
222706f2543Smrg    (*set_origin)(xf86CrtcPtr crtc, int x, int y);
223706f2543Smrg
224706f2543Smrg} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr;
225706f2543Smrg
226706f2543Smrg#define XF86_CRTC_VERSION 3
227706f2543Smrg
228706f2543Smrgstruct _xf86Crtc {
229706f2543Smrg    /**
230706f2543Smrg     * ABI versioning
231706f2543Smrg     */
232706f2543Smrg    int version;
233706f2543Smrg
234706f2543Smrg    /**
235706f2543Smrg     * Associated ScrnInfo
236706f2543Smrg     */
237706f2543Smrg    ScrnInfoPtr	    scrn;
238706f2543Smrg
239706f2543Smrg    /**
240706f2543Smrg     * Desired state of this CRTC
241706f2543Smrg     *
242706f2543Smrg     * Set when this CRTC should be driving one or more outputs
243706f2543Smrg     */
244706f2543Smrg    Bool	    enabled;
245706f2543Smrg
246706f2543Smrg    /**
247706f2543Smrg     * Active mode
248706f2543Smrg     *
249706f2543Smrg     * This reflects the mode as set in the CRTC currently
250706f2543Smrg     * It will be cleared when the VT is not active or
251706f2543Smrg     * during server startup
252706f2543Smrg     */
253706f2543Smrg    DisplayModeRec  mode;
254706f2543Smrg    Rotation	    rotation;
255706f2543Smrg    PixmapPtr	    rotatedPixmap;
256706f2543Smrg    void	    *rotatedData;
257706f2543Smrg
258706f2543Smrg    /**
259706f2543Smrg     * Position on screen
260706f2543Smrg     *
261706f2543Smrg     * Locates this CRTC within the frame buffer
262706f2543Smrg     */
263706f2543Smrg    int		    x, y;
264706f2543Smrg
265706f2543Smrg    /**
266706f2543Smrg     * Desired mode
267706f2543Smrg     *
268706f2543Smrg     * This is set to the requested mode, independent of
269706f2543Smrg     * whether the VT is active. In particular, it receives
270706f2543Smrg     * the startup configured mode and saves the active mode
271706f2543Smrg     * on VT switch.
272706f2543Smrg     */
273706f2543Smrg    DisplayModeRec  desiredMode;
274706f2543Smrg    Rotation	    desiredRotation;
275706f2543Smrg    int		    desiredX, desiredY;
276706f2543Smrg
277706f2543Smrg    /** crtc-specific functions */
278706f2543Smrg    const xf86CrtcFuncsRec *funcs;
279706f2543Smrg
280706f2543Smrg    /**
281706f2543Smrg     * Driver private
282706f2543Smrg     *
283706f2543Smrg     * Holds driver-private information
284706f2543Smrg     */
285706f2543Smrg    void	    *driver_private;
286706f2543Smrg
287706f2543Smrg#ifdef RANDR_12_INTERFACE
288706f2543Smrg    /**
289706f2543Smrg     * RandR crtc
290706f2543Smrg     *
291706f2543Smrg     * When RandR 1.2 is available, this
292706f2543Smrg     * points at the associated crtc object
293706f2543Smrg     */
294706f2543Smrg    RRCrtcPtr	    randr_crtc;
295706f2543Smrg#else
296706f2543Smrg    void	    *randr_crtc;
297706f2543Smrg#endif
298706f2543Smrg
299706f2543Smrg    /**
300706f2543Smrg     * Current cursor is ARGB
301706f2543Smrg     */
302706f2543Smrg    Bool	    cursor_argb;
303706f2543Smrg    /**
304706f2543Smrg     * Track whether cursor is within CRTC range
305706f2543Smrg     */
306706f2543Smrg    Bool	    cursor_in_range;
307706f2543Smrg    /**
308706f2543Smrg     * Track state of cursor associated with this CRTC
309706f2543Smrg     */
310706f2543Smrg    Bool	    cursor_shown;
311706f2543Smrg
312706f2543Smrg    /**
313706f2543Smrg     * Current transformation matrix
314706f2543Smrg     */
315706f2543Smrg    PictTransform   crtc_to_framebuffer;
316706f2543Smrg    /* framebuffer_to_crtc was removed in ABI 2 */
317706f2543Smrg    struct pict_f_transform f_crtc_to_framebuffer; /* ABI 2 */
318706f2543Smrg    struct pict_f_transform f_framebuffer_to_crtc; /* ABI 2 */
319706f2543Smrg    PictFilterPtr   filter; /* ABI 2 */
320706f2543Smrg    xFixed	    *params; /* ABI 2 */
321706f2543Smrg    int		    nparams; /* ABI 2 */
322706f2543Smrg    int		    filter_width; /* ABI 2 */
323706f2543Smrg    int		    filter_height; /* ABI 2 */
324706f2543Smrg    Bool	    transform_in_use;
325706f2543Smrg    RRTransformRec  transform; /* ABI 2 */
326706f2543Smrg    Bool	    transformPresent; /* ABI 2 */
327706f2543Smrg    RRTransformRec  desiredTransform; /* ABI 2 */
328706f2543Smrg    Bool	    desiredTransformPresent; /* ABI 2 */
329706f2543Smrg    /**
330706f2543Smrg     * Bounding box in screen space
331706f2543Smrg     */
332706f2543Smrg    BoxRec	    bounds;
333706f2543Smrg    /**
334706f2543Smrg     * Panning:
335706f2543Smrg     * TotalArea: total panning area, larger than CRTC's size
336706f2543Smrg     * TrackingArea: Area of the pointer for which the CRTC is panned
337706f2543Smrg     * border: Borders of the displayed CRTC area which induces panning if the pointer reaches them
338706f2543Smrg     * Added in ABI version 2
339706f2543Smrg     */
340706f2543Smrg    BoxRec          panningTotalArea;
341706f2543Smrg    BoxRec          panningTrackingArea;
342706f2543Smrg    INT16           panningBorder[4];
343706f2543Smrg
344706f2543Smrg    /**
345706f2543Smrg     * Current gamma, especially useful after initial config.
346706f2543Smrg     * Added in ABI version 3
347706f2543Smrg     */
348706f2543Smrg    CARD16 *gamma_red;
349706f2543Smrg    CARD16 *gamma_green;
350706f2543Smrg    CARD16 *gamma_blue;
351706f2543Smrg    int gamma_size;
352706f2543Smrg
353706f2543Smrg    /**
354706f2543Smrg     * Actual state of this CRTC
355706f2543Smrg     *
356706f2543Smrg     * Set to TRUE after modesetting, set to FALSE if no outputs are connected
357706f2543Smrg     * Added in ABI version 3
358706f2543Smrg     */
359706f2543Smrg    Bool	    active;
360706f2543Smrg    /**
361706f2543Smrg     * Clear the shadow
362706f2543Smrg     */
363706f2543Smrg    Bool	    shadowClear;
364706f2543Smrg};
365706f2543Smrg
366706f2543Smrgtypedef struct _xf86OutputFuncs {
367706f2543Smrg    /**
368706f2543Smrg     * Called to allow the output a chance to create properties after the
369706f2543Smrg     * RandR objects have been created.
370706f2543Smrg     */
371706f2543Smrg    void
372706f2543Smrg    (*create_resources)(xf86OutputPtr output);
373706f2543Smrg
374706f2543Smrg    /**
375706f2543Smrg     * Turns the output on/off, or sets intermediate power levels if available.
376706f2543Smrg     *
377706f2543Smrg     * Unsupported intermediate modes drop to the lower power setting.  If the
378706f2543Smrg     * mode is DPMSModeOff, the output must be disabled, as the DPLL may be
379706f2543Smrg     * disabled afterwards.
380706f2543Smrg     */
381706f2543Smrg    void
382706f2543Smrg    (*dpms)(xf86OutputPtr	output,
383706f2543Smrg	    int			mode);
384706f2543Smrg
385706f2543Smrg    /**
386706f2543Smrg     * Saves the output's state for restoration on VT switch.
387706f2543Smrg     */
388706f2543Smrg    void
389706f2543Smrg    (*save)(xf86OutputPtr	output);
390706f2543Smrg
391706f2543Smrg    /**
392706f2543Smrg     * Restore's the output's state at VT switch.
393706f2543Smrg     */
394706f2543Smrg    void
395706f2543Smrg    (*restore)(xf86OutputPtr	output);
396706f2543Smrg
397706f2543Smrg    /**
398706f2543Smrg     * Callback for testing a video mode for a given output.
399706f2543Smrg     *
400706f2543Smrg     * This function should only check for cases where a mode can't be supported
401706f2543Smrg     * on the output specifically, and not represent generic CRTC limitations.
402706f2543Smrg     *
403706f2543Smrg     * \return MODE_OK if the mode is valid, or another MODE_* otherwise.
404706f2543Smrg     */
405706f2543Smrg    int
406706f2543Smrg    (*mode_valid)(xf86OutputPtr	    output,
407706f2543Smrg		  DisplayModePtr    pMode);
408706f2543Smrg
409706f2543Smrg    /**
410706f2543Smrg     * Callback to adjust the mode to be set in the CRTC.
411706f2543Smrg     *
412706f2543Smrg     * This allows an output to adjust the clock or even the entire set of
413706f2543Smrg     * timings, which is used for panels with fixed timings or for
414706f2543Smrg     * buses with clock limitations.
415706f2543Smrg     */
416706f2543Smrg    Bool
417706f2543Smrg    (*mode_fixup)(xf86OutputPtr output,
418706f2543Smrg		  DisplayModePtr mode,
419706f2543Smrg		  DisplayModePtr adjusted_mode);
420706f2543Smrg
421706f2543Smrg    /**
422706f2543Smrg     * Callback for preparing mode changes on an output
423706f2543Smrg     */
424706f2543Smrg    void
425706f2543Smrg    (*prepare)(xf86OutputPtr output);
426706f2543Smrg
427706f2543Smrg    /**
428706f2543Smrg     * Callback for committing mode changes on an output
429706f2543Smrg     */
430706f2543Smrg    void
431706f2543Smrg    (*commit)(xf86OutputPtr output);
432706f2543Smrg
433706f2543Smrg    /**
434706f2543Smrg     * Callback for setting up a video mode after fixups have been made.
435706f2543Smrg     *
436706f2543Smrg     * This is only called while the output is disabled.  The dpms callback
437706f2543Smrg     * must be all that's necessary for the output, to turn the output on
438706f2543Smrg     * after this function is called.
439706f2543Smrg     */
440706f2543Smrg    void
441706f2543Smrg    (*mode_set)(xf86OutputPtr  output,
442706f2543Smrg		DisplayModePtr mode,
443706f2543Smrg		DisplayModePtr adjusted_mode);
444706f2543Smrg
445706f2543Smrg    /**
446706f2543Smrg     * Probe for a connected output, and return detect_status.
447706f2543Smrg     */
448706f2543Smrg    xf86OutputStatus
449706f2543Smrg    (*detect)(xf86OutputPtr	    output);
450706f2543Smrg
451706f2543Smrg    /**
452706f2543Smrg     * Query the device for the modes it provides.
453706f2543Smrg     *
454706f2543Smrg     * This function may also update MonInfo, mm_width, and mm_height.
455706f2543Smrg     *
456706f2543Smrg     * \return singly-linked list of modes or NULL if no modes found.
457706f2543Smrg     */
458706f2543Smrg    DisplayModePtr
459706f2543Smrg    (*get_modes)(xf86OutputPtr	    output);
460706f2543Smrg
461706f2543Smrg#ifdef RANDR_12_INTERFACE
462706f2543Smrg    /**
463706f2543Smrg     * Callback when an output's property has changed.
464706f2543Smrg     */
465706f2543Smrg    Bool
466706f2543Smrg    (*set_property)(xf86OutputPtr output,
467706f2543Smrg		    Atom property,
468706f2543Smrg		    RRPropertyValuePtr value);
469706f2543Smrg#endif
470706f2543Smrg#ifdef RANDR_13_INTERFACE
471706f2543Smrg    /**
472706f2543Smrg     * Callback to get an updated property value
473706f2543Smrg     */
474706f2543Smrg    Bool
475706f2543Smrg    (*get_property)(xf86OutputPtr output,
476706f2543Smrg		    Atom property);
477706f2543Smrg#endif
478706f2543Smrg#ifdef RANDR_GET_CRTC_INTERFACE
479706f2543Smrg    /**
480706f2543Smrg     * Callback to get current CRTC for a given output
481706f2543Smrg     */
482706f2543Smrg    xf86CrtcPtr
483706f2543Smrg    (*get_crtc)(xf86OutputPtr output);
484706f2543Smrg#endif
485706f2543Smrg    /**
486706f2543Smrg     * Clean up driver-specific bits of the output
487706f2543Smrg     */
488706f2543Smrg    void
489706f2543Smrg    (*destroy) (xf86OutputPtr	    output);
490706f2543Smrg} xf86OutputFuncsRec, *xf86OutputFuncsPtr;
491706f2543Smrg
492706f2543Smrg
493706f2543Smrg#define XF86_OUTPUT_VERSION 2
494706f2543Smrg
495706f2543Smrgstruct _xf86Output {
496706f2543Smrg    /**
497706f2543Smrg     * ABI versioning
498706f2543Smrg     */
499706f2543Smrg    int version;
500706f2543Smrg
501706f2543Smrg    /**
502706f2543Smrg     * Associated ScrnInfo
503706f2543Smrg     */
504706f2543Smrg    ScrnInfoPtr		scrn;
505706f2543Smrg
506706f2543Smrg    /**
507706f2543Smrg     * Currently connected crtc (if any)
508706f2543Smrg     *
509706f2543Smrg     * If this output is not in use, this field will be NULL.
510706f2543Smrg     */
511706f2543Smrg    xf86CrtcPtr		crtc;
512706f2543Smrg
513706f2543Smrg    /**
514706f2543Smrg     * Possible CRTCs for this output as a mask of crtc indices
515706f2543Smrg     */
516706f2543Smrg    CARD32		possible_crtcs;
517706f2543Smrg
518706f2543Smrg    /**
519706f2543Smrg     * Possible outputs to share the same CRTC as a mask of output indices
520706f2543Smrg     */
521706f2543Smrg    CARD32		possible_clones;
522706f2543Smrg
523706f2543Smrg    /**
524706f2543Smrg     * Whether this output can support interlaced modes
525706f2543Smrg     */
526706f2543Smrg    Bool		interlaceAllowed;
527706f2543Smrg
528706f2543Smrg    /**
529706f2543Smrg     * Whether this output can support double scan modes
530706f2543Smrg     */
531706f2543Smrg    Bool		doubleScanAllowed;
532706f2543Smrg
533706f2543Smrg    /**
534706f2543Smrg     * List of available modes on this output.
535706f2543Smrg     *
536706f2543Smrg     * This should be the list from get_modes(), plus perhaps additional
537706f2543Smrg     * compatible modes added later.
538706f2543Smrg     */
539706f2543Smrg    DisplayModePtr	probed_modes;
540706f2543Smrg
541706f2543Smrg    /**
542706f2543Smrg     * Options parsed from the related monitor section
543706f2543Smrg     */
544706f2543Smrg    OptionInfoPtr	options;
545706f2543Smrg
546706f2543Smrg    /**
547706f2543Smrg     * Configured monitor section
548706f2543Smrg     */
549706f2543Smrg    XF86ConfMonitorPtr  conf_monitor;
550706f2543Smrg
551706f2543Smrg    /**
552706f2543Smrg     * Desired initial position
553706f2543Smrg     */
554706f2543Smrg    int			initial_x, initial_y;
555706f2543Smrg
556706f2543Smrg    /**
557706f2543Smrg     * Desired initial rotation
558706f2543Smrg     */
559706f2543Smrg    Rotation		initial_rotation;
560706f2543Smrg
561706f2543Smrg    /**
562706f2543Smrg     * Current connection status
563706f2543Smrg     *
564706f2543Smrg     * This indicates whether a monitor is known to be connected
565706f2543Smrg     * to this output or not, or whether there is no way to tell
566706f2543Smrg     */
567706f2543Smrg    xf86OutputStatus	status;
568706f2543Smrg
569706f2543Smrg    /** EDID monitor information */
570706f2543Smrg    xf86MonPtr		MonInfo;
571706f2543Smrg
572706f2543Smrg    /** subpixel order */
573706f2543Smrg    int			subpixel_order;
574706f2543Smrg
575706f2543Smrg    /** Physical size of the currently attached output device. */
576706f2543Smrg    int			mm_width, mm_height;
577706f2543Smrg
578706f2543Smrg    /** Output name */
579706f2543Smrg    char		*name;
580706f2543Smrg
581706f2543Smrg    /** output-specific functions */
582706f2543Smrg    const xf86OutputFuncsRec *funcs;
583706f2543Smrg
584706f2543Smrg    /** driver private information */
585706f2543Smrg    void		*driver_private;
586706f2543Smrg
587706f2543Smrg    /** Whether to use the old per-screen Monitor config section */
588706f2543Smrg    Bool		use_screen_monitor;
589706f2543Smrg
590706f2543Smrg#ifdef RANDR_12_INTERFACE
591706f2543Smrg    /**
592706f2543Smrg     * RandR 1.2 output structure.
593706f2543Smrg     *
594706f2543Smrg     * When RandR 1.2 is available, this points at the associated
595706f2543Smrg     * RandR output structure and is created when this output is created
596706f2543Smrg     */
597706f2543Smrg    RROutputPtr		randr_output;
598706f2543Smrg#else
599706f2543Smrg    void		*randr_output;
600706f2543Smrg#endif
601706f2543Smrg    /**
602706f2543Smrg     * Desired initial panning
603706f2543Smrg     * Added in ABI version 2
604706f2543Smrg     */
605706f2543Smrg    BoxRec          initialTotalArea;
606706f2543Smrg    BoxRec          initialTrackingArea;
607706f2543Smrg    INT16           initialBorder[4];
608706f2543Smrg};
609706f2543Smrg
610706f2543Smrgtypedef struct _xf86CrtcConfigFuncs {
611706f2543Smrg    /**
612706f2543Smrg     * Requests that the driver resize the screen.
613706f2543Smrg     *
614706f2543Smrg     * The driver is responsible for updating scrn->virtualX and scrn->virtualY.
615706f2543Smrg     * If the requested size cannot be set, the driver should leave those values
616706f2543Smrg     * alone and return FALSE.
617706f2543Smrg     *
618706f2543Smrg     * A naive driver that cannot reallocate the screen may simply change
619706f2543Smrg     * virtual[XY].  A more advanced driver will want to also change the
620706f2543Smrg     * devPrivate.ptr and devKind of the screen pixmap, update any offscreen
621706f2543Smrg     * pixmaps it may have moved, and change pScrn->displayWidth.
622706f2543Smrg     */
623706f2543Smrg    Bool
624706f2543Smrg    (*resize)(ScrnInfoPtr	scrn,
625706f2543Smrg	      int		width,
626706f2543Smrg	      int		height);
627706f2543Smrg} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr;
628706f2543Smrg
629706f2543Smrgtypedef void (*xf86_crtc_notify_proc_ptr) (ScreenPtr pScreen);
630706f2543Smrg
631706f2543Smrgtypedef struct _xf86CrtcConfig {
632706f2543Smrg    int			num_output;
633706f2543Smrg    xf86OutputPtr	*output;
634706f2543Smrg    /**
635706f2543Smrg     * compat_output is used whenever we deal
636706f2543Smrg     * with legacy code that only understands a single
637706f2543Smrg     * output. pScrn->modes will be loaded from this output,
638706f2543Smrg     * adjust frame will whack this output, etc.
639706f2543Smrg     */
640706f2543Smrg    int			compat_output;
641706f2543Smrg
642706f2543Smrg    int			num_crtc;
643706f2543Smrg    xf86CrtcPtr		*crtc;
644706f2543Smrg
645706f2543Smrg    int			minWidth, minHeight;
646706f2543Smrg    int			maxWidth, maxHeight;
647706f2543Smrg
648706f2543Smrg    /* For crtc-based rotation */
649706f2543Smrg    DamagePtr		rotation_damage;
650706f2543Smrg    Bool		rotation_damage_registered;
651706f2543Smrg
652706f2543Smrg    /* DGA */
653706f2543Smrg    unsigned int	dga_flags;
654706f2543Smrg    unsigned long	dga_address;
655706f2543Smrg    DGAModePtr		dga_modes;
656706f2543Smrg    int			dga_nmode;
657706f2543Smrg    int			dga_width, dga_height, dga_stride;
658706f2543Smrg    DisplayModePtr	dga_save_mode;
659706f2543Smrg
660706f2543Smrg    const xf86CrtcConfigFuncsRec *funcs;
661706f2543Smrg
662706f2543Smrg    CreateScreenResourcesProcPtr    CreateScreenResources;
663706f2543Smrg
664706f2543Smrg    CloseScreenProcPtr		    CloseScreen;
665706f2543Smrg
666706f2543Smrg    /* Cursor information */
667706f2543Smrg    xf86CursorInfoPtr	cursor_info;
668706f2543Smrg    CursorPtr		cursor;
669706f2543Smrg    CARD8		*cursor_image;
670706f2543Smrg    Bool		cursor_on;
671706f2543Smrg    CARD32		cursor_fg, cursor_bg;
672706f2543Smrg
673706f2543Smrg    /**
674706f2543Smrg     * Options parsed from the related device section
675706f2543Smrg     */
676706f2543Smrg    OptionInfoPtr	options;
677706f2543Smrg
678706f2543Smrg    Bool		debug_modes;
679706f2543Smrg
680706f2543Smrg    /* wrap screen BlockHandler for rotation */
681706f2543Smrg    ScreenBlockHandlerProcPtr	BlockHandler;
682706f2543Smrg
683706f2543Smrg    /* callback when crtc configuration changes */
684706f2543Smrg    xf86_crtc_notify_proc_ptr  xf86_crtc_notify;
685706f2543Smrg
686706f2543Smrg} xf86CrtcConfigRec, *xf86CrtcConfigPtr;
687706f2543Smrg
688706f2543Smrgextern _X_EXPORT int xf86CrtcConfigPrivateIndex;
689706f2543Smrg
690706f2543Smrg#define XF86_CRTC_CONFIG_PTR(p)	((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr))
691706f2543Smrg
692706f2543Smrgstatic _X_INLINE xf86OutputPtr
693706f2543Smrgxf86CompatOutput(ScrnInfoPtr pScrn)
694706f2543Smrg{
695706f2543Smrg    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
696706f2543Smrg    return config->output[config->compat_output];
697706f2543Smrg}
698706f2543Smrg
699706f2543Smrgstatic _X_INLINE xf86CrtcPtr
700706f2543Smrgxf86CompatCrtc(ScrnInfoPtr pScrn)
701706f2543Smrg{
702706f2543Smrg    xf86OutputPtr compat_output = xf86CompatOutput(pScrn);
703706f2543Smrg    if (!compat_output)
704706f2543Smrg	return NULL;
705706f2543Smrg    return compat_output->crtc;
706706f2543Smrg}
707706f2543Smrg
708706f2543Smrgstatic _X_INLINE RRCrtcPtr
709706f2543Smrgxf86CompatRRCrtc(ScrnInfoPtr pScrn)
710706f2543Smrg{
711706f2543Smrg    xf86CrtcPtr	compat_crtc = xf86CompatCrtc(pScrn);
712706f2543Smrg    if (!compat_crtc)
713706f2543Smrg	return NULL;
714706f2543Smrg    return compat_crtc->randr_crtc;
715706f2543Smrg}
716706f2543Smrg
717706f2543Smrg
718706f2543Smrg/*
719706f2543Smrg * Initialize xf86CrtcConfig structure
720706f2543Smrg */
721706f2543Smrg
722706f2543Smrgextern _X_EXPORT void
723706f2543Smrgxf86CrtcConfigInit (ScrnInfoPtr				scrn,
724706f2543Smrg		    const xf86CrtcConfigFuncsRec	*funcs);
725706f2543Smrg
726706f2543Smrgextern _X_EXPORT void
727706f2543Smrgxf86CrtcSetSizeRange (ScrnInfoPtr scrn,
728706f2543Smrg		      int minWidth, int minHeight,
729706f2543Smrg		      int maxWidth, int maxHeight);
730706f2543Smrg
731706f2543Smrg/*
732706f2543Smrg * Crtc functions
733706f2543Smrg */
734706f2543Smrgextern _X_EXPORT xf86CrtcPtr
735706f2543Smrgxf86CrtcCreate (ScrnInfoPtr		scrn,
736706f2543Smrg		const xf86CrtcFuncsRec	*funcs);
737706f2543Smrg
738706f2543Smrgextern _X_EXPORT void
739706f2543Smrgxf86CrtcDestroy (xf86CrtcPtr		crtc);
740706f2543Smrg
741706f2543Smrg
742706f2543Smrg/**
743706f2543Smrg * Sets the given video mode on the given crtc
744706f2543Smrg */
745706f2543Smrg
746706f2543Smrgextern _X_EXPORT Bool
747706f2543Smrgxf86CrtcSetModeTransform (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
748706f2543Smrg			  RRTransformPtr transform, int x, int y);
749706f2543Smrg
750706f2543Smrgextern _X_EXPORT Bool
751706f2543Smrgxf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation,
752706f2543Smrg		 int x, int y);
753706f2543Smrg
754706f2543Smrgextern _X_EXPORT void
755706f2543Smrgxf86CrtcSetOrigin (xf86CrtcPtr crtc, int x, int y);
756706f2543Smrg
757706f2543Smrg/*
758706f2543Smrg * Assign crtc rotation during mode set
759706f2543Smrg */
760706f2543Smrgextern _X_EXPORT Bool
761706f2543Smrgxf86CrtcRotate (xf86CrtcPtr crtc);
762706f2543Smrg
763706f2543Smrg/*
764706f2543Smrg * Clean up any rotation data, used when a crtc is turned off
765706f2543Smrg * as well as when rotation is disabled.
766706f2543Smrg */
767706f2543Smrgextern _X_EXPORT void
768706f2543Smrgxf86RotateDestroy (xf86CrtcPtr crtc);
769706f2543Smrg
770706f2543Smrg/*
771706f2543Smrg * free shadow memory allocated for all crtcs
772706f2543Smrg */
773706f2543Smrgextern _X_EXPORT void
774706f2543Smrgxf86RotateFreeShadow(ScrnInfoPtr pScrn);
775706f2543Smrg
776706f2543Smrg/*
777706f2543Smrg * Clean up rotation during CloseScreen
778706f2543Smrg */
779706f2543Smrgextern _X_EXPORT void
780706f2543Smrgxf86RotateCloseScreen (ScreenPtr pScreen);
781706f2543Smrg
782706f2543Smrg/**
783706f2543Smrg * Return whether any output is assigned to the crtc
784706f2543Smrg */
785706f2543Smrgextern _X_EXPORT Bool
786706f2543Smrgxf86CrtcInUse (xf86CrtcPtr crtc);
787706f2543Smrg
788706f2543Smrg/*
789706f2543Smrg * Output functions
790706f2543Smrg */
791706f2543Smrgextern _X_EXPORT xf86OutputPtr
792706f2543Smrgxf86OutputCreate (ScrnInfoPtr		    scrn,
793706f2543Smrg		  const xf86OutputFuncsRec  *funcs,
794706f2543Smrg		  const char		    *name);
795706f2543Smrg
796706f2543Smrgextern _X_EXPORT void
797706f2543Smrgxf86OutputUseScreenMonitor (xf86OutputPtr output, Bool use_screen_monitor);
798706f2543Smrg
799706f2543Smrgextern _X_EXPORT Bool
800706f2543Smrgxf86OutputRename (xf86OutputPtr output, const char *name);
801706f2543Smrg
802706f2543Smrgextern _X_EXPORT void
803706f2543Smrgxf86OutputDestroy (xf86OutputPtr	output);
804706f2543Smrg
805706f2543Smrgextern _X_EXPORT void
806706f2543Smrgxf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY);
807706f2543Smrg
808706f2543Smrgextern _X_EXPORT void
809706f2543Smrgxf86SetScrnInfoModes (ScrnInfoPtr pScrn);
810706f2543Smrg
811706f2543Smrg#ifdef RANDR_13_INTERFACE
812706f2543Smrg# define ScreenInitRetType	int
813706f2543Smrg#else
814706f2543Smrg# define ScreenInitRetType	Bool
815706f2543Smrg#endif
816706f2543Smrg
817706f2543Smrgextern _X_EXPORT ScreenInitRetType
818706f2543Smrgxf86CrtcScreenInit (ScreenPtr pScreen);
819706f2543Smrg
820706f2543Smrgextern _X_EXPORT Bool
821706f2543Smrgxf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow);
822706f2543Smrg
823706f2543Smrgextern _X_EXPORT void
824706f2543Smrgxf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags);
825706f2543Smrg
826706f2543Smrgextern _X_EXPORT Bool
827706f2543Smrgxf86SaveScreen(ScreenPtr pScreen, int mode);
828706f2543Smrg
829706f2543Smrgextern _X_EXPORT void
830706f2543Smrgxf86DisableUnusedFunctions(ScrnInfoPtr pScrn);
831706f2543Smrg
832706f2543Smrgextern _X_EXPORT DisplayModePtr
833706f2543Smrgxf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired);
834706f2543Smrg
835706f2543Smrgextern _X_EXPORT Bool
836706f2543Smrgxf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation);
837706f2543Smrg
838706f2543Smrg/**
839706f2543Smrg * Set the EDID information for the specified output
840706f2543Smrg */
841706f2543Smrgextern _X_EXPORT void
842706f2543Smrgxf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon);
843706f2543Smrg
844706f2543Smrg/**
845706f2543Smrg * Return the list of modes supported by the EDID information
846706f2543Smrg * stored in 'output'
847706f2543Smrg */
848706f2543Smrgextern _X_EXPORT DisplayModePtr
849706f2543Smrgxf86OutputGetEDIDModes (xf86OutputPtr output);
850706f2543Smrg
851706f2543Smrgextern _X_EXPORT xf86MonPtr
852706f2543Smrgxf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus);
853706f2543Smrg
854706f2543Smrg/**
855706f2543Smrg * Initialize dga for this screen
856706f2543Smrg */
857706f2543Smrg
858706f2543Smrg#ifdef XFreeXDGA
859706f2543Smrgextern _X_EXPORT Bool
860706f2543Smrgxf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address);
861706f2543Smrg
862706f2543Smrg/* this is the real function, used only internally */
863706f2543Smrg_X_INTERNAL Bool
864706f2543Smrg_xf86_di_dga_init_internal (ScreenPtr pScreen);
865706f2543Smrg
866706f2543Smrg/**
867706f2543Smrg * Re-initialize dga for this screen (as when the set of modes changes)
868706f2543Smrg */
869706f2543Smrg
870706f2543Smrgextern _X_EXPORT Bool
871706f2543Smrgxf86DiDGAReInit (ScreenPtr pScreen);
872706f2543Smrg#endif
873706f2543Smrg
874706f2543Smrg/* This is the real function, used only internally */
875706f2543Smrg_X_INTERNAL Bool
876706f2543Smrg_xf86_di_dga_reinit_internal (ScreenPtr pScreen);
877706f2543Smrg
878706f2543Smrg/*
879706f2543Smrg * Set the subpixel order reported for the screen using
880706f2543Smrg * the information from the outputs
881706f2543Smrg */
882706f2543Smrg
883706f2543Smrgextern _X_EXPORT void
884706f2543Smrgxf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen);
885706f2543Smrg
886706f2543Smrg/*
887706f2543Smrg * Get a standard string name for a connector type
888706f2543Smrg */
889706f2543Smrgextern _X_EXPORT char *
890706f2543Smrgxf86ConnectorGetName(xf86ConnectorType connector);
891706f2543Smrg
892706f2543Smrg/*
893706f2543Smrg * Using the desired mode information in each crtc, set
894706f2543Smrg * modes (used in EnterVT functions, or at server startup)
895706f2543Smrg */
896706f2543Smrg
897706f2543Smrgextern _X_EXPORT Bool
898706f2543Smrgxf86SetDesiredModes (ScrnInfoPtr pScrn);
899706f2543Smrg
900706f2543Smrg/**
901706f2543Smrg * Initialize the CRTC-based cursor code. CRTC function vectors must
902706f2543Smrg * contain relevant cursor setting functions.
903706f2543Smrg *
904706f2543Smrg * Driver should call this from ScreenInit function
905706f2543Smrg */
906706f2543Smrgextern _X_EXPORT Bool
907706f2543Smrgxf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags);
908706f2543Smrg
909706f2543Smrg/**
910706f2543Smrg * Called when anything on the screen is reconfigured.
911706f2543Smrg *
912706f2543Smrg * Reloads cursor images as needed, then adjusts cursor positions.
913706f2543Smrg *
914706f2543Smrg * Driver should call this from crtc commit function.
915706f2543Smrg */
916706f2543Smrgextern _X_EXPORT void
917706f2543Smrgxf86_reload_cursors (ScreenPtr screen);
918706f2543Smrg
919706f2543Smrg/**
920706f2543Smrg * Called from EnterVT to turn the cursors back on
921706f2543Smrg */
922706f2543Smrgextern _X_EXPORT void
923706f2543Smrgxf86_show_cursors (ScrnInfoPtr scrn);
924706f2543Smrg
925706f2543Smrg/**
926706f2543Smrg * Called by the driver to turn cursors off
927706f2543Smrg */
928706f2543Smrgextern _X_EXPORT void
929706f2543Smrgxf86_hide_cursors (ScrnInfoPtr scrn);
930706f2543Smrg
931706f2543Smrg/**
932706f2543Smrg * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time.
933706f2543Smrg */
934706f2543Smrgextern _X_EXPORT void
935706f2543Smrgxf86_cursors_fini (ScreenPtr screen);
936706f2543Smrg
937706f2543Smrg/*
938706f2543Smrg * For overlay video, compute the relevant CRTC and
939706f2543Smrg * clip video to that.
940706f2543Smrg * wraps xf86XVClipVideoHelper()
941706f2543Smrg */
942706f2543Smrg
943706f2543Smrgextern _X_EXPORT Bool
944706f2543Smrgxf86_crtc_clip_video_helper(ScrnInfoPtr pScrn,
945706f2543Smrg			    xf86CrtcPtr *crtc_ret,
946706f2543Smrg			    xf86CrtcPtr desired_crtc,
947706f2543Smrg			    BoxPtr      dst,
948706f2543Smrg			    INT32	*xa,
949706f2543Smrg			    INT32	*xb,
950706f2543Smrg			    INT32	*ya,
951706f2543Smrg			    INT32	*yb,
952706f2543Smrg			    RegionPtr   reg,
953706f2543Smrg			    INT32	width,
954706f2543Smrg			    INT32	height);
955706f2543Smrg
956706f2543Smrgextern _X_EXPORT xf86_crtc_notify_proc_ptr
957706f2543Smrgxf86_wrap_crtc_notify (ScreenPtr pScreen, xf86_crtc_notify_proc_ptr new);
958706f2543Smrg
959706f2543Smrgextern _X_EXPORT void
960706f2543Smrgxf86_unwrap_crtc_notify(ScreenPtr pScreen, xf86_crtc_notify_proc_ptr old);
961706f2543Smrg
962706f2543Smrgextern _X_EXPORT void
963706f2543Smrgxf86_crtc_notify(ScreenPtr pScreen);
964706f2543Smrg
965706f2543Smrg/**
966706f2543Smrg * Gamma
967706f2543Smrg */
968706f2543Smrg
969706f2543Smrgextern _X_EXPORT Bool
970706f2543Smrgxf86_crtc_supports_gamma(ScrnInfoPtr pScrn);
971706f2543Smrg
972706f2543Smrg#endif /* _XF86CRTC_H_ */
973