2 * Copyright © 2000 Compaq Computer Corporation
3 * Copyright © 2002 Hewlett-Packard Company
4 * Copyright © 2006 Intel Corporation
5 * Copyright © 2008 Red Hat, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that copyright
10 * notice and this permission notice appear in supporting documentation, and
11 * that the name of the copyright holders not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no representations
14 * about the suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 * Author: Jim Gettys, Hewlett-Packard Company, Inc.
26 * Keith Packard, Intel Corporation
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
37 #include <X11/Xproto.h>
40 #include "dixstruct.h"
42 #include "scrnintstr.h"
43 #include "windowstr.h"
44 #include "pixmapstr.h"
45 #include "extnsionst.h"
47 #include "rrtransform.h"
48 #include <X11/extensions/randr.h>
49 #include <X11/extensions/randrproto.h>
50 #include <X11/extensions/render.h> /* we share subpixel order information */
51 #include "picturestr.h"
52 #include <X11/Xfuncproto.h>
54 /* required for ABI compatibility for now */
55 #define RANDR_10_INTERFACE 1
56 #define RANDR_12_INTERFACE 1
57 #define RANDR_13_INTERFACE 1 /* requires RANDR_12_INTERFACE */
58 #define RANDR_GET_CRTC_INTERFACE 1
60 #define RANDR_INTERFACE_VERSION 0x0103
66 extern _X_EXPORT
int RREventBase
, RRErrorBase
;
68 extern _X_EXPORT
int (*ProcRandrVector
[RRNumberRequests
]) (ClientPtr
);
69 extern _X_EXPORT
int (*SProcRandrVector
[RRNumberRequests
]) (ClientPtr
);
72 * Modeline for a monitor. Name follows directly after this struct
75 #define RRModeName(pMode) ((char *) (pMode + 1))
76 typedef struct _rrMode RRModeRec
, *RRModePtr
;
77 typedef struct _rrPropertyValue RRPropertyValueRec
, *RRPropertyValuePtr
;
78 typedef struct _rrProperty RRPropertyRec
, *RRPropertyPtr
;
79 typedef struct _rrCrtc RRCrtcRec
, *RRCrtcPtr
;
80 typedef struct _rrOutput RROutputRec
, *RROutputPtr
;
89 struct _rrPropertyValue
{
90 Atom type
; /* ignored by server */
91 short format
; /* format of data for swapping - 8,16,32 */
92 long size
; /* size of data in (format/8) bytes */
93 pointer data
; /* private to client */
104 RRPropertyValueRec current
, pending
;
116 RROutputPtr
*outputs
;
123 RRTransformRec client_pending_transform
;
124 RRTransformRec client_current_transform
;
125 PictTransform transform
;
126 struct pict_f_transform f_transform
;
127 struct pict_f_transform f_inverse
;
148 RRModePtr
*userModes
;
150 RRPropertyPtr properties
;
151 Bool pendingProperties
;
155 #if RANDR_12_INTERFACE
156 typedef Bool (*RRScreenSetSizeProcPtr
) (ScreenPtr pScreen
,
159 CARD32 mmWidth
, CARD32 mmHeight
);
161 typedef Bool (*RRCrtcSetProcPtr
) (ScreenPtr pScreen
,
167 int numOutputs
, RROutputPtr
* outputs
);
169 typedef Bool (*RRCrtcSetGammaProcPtr
) (ScreenPtr pScreen
, RRCrtcPtr crtc
);
171 typedef Bool (*RRCrtcGetGammaProcPtr
) (ScreenPtr pScreen
, RRCrtcPtr crtc
);
173 typedef Bool (*RROutputSetPropertyProcPtr
) (ScreenPtr pScreen
,
176 RRPropertyValuePtr value
);
178 typedef Bool (*RROutputValidateModeProcPtr
) (ScreenPtr pScreen
,
182 typedef void (*RRModeDestroyProcPtr
) (ScreenPtr pScreen
, RRModePtr mode
);
186 #if RANDR_13_INTERFACE
187 typedef Bool (*RROutputGetPropertyProcPtr
) (ScreenPtr pScreen
,
188 RROutputPtr output
, Atom property
);
189 typedef Bool (*RRGetPanningProcPtr
) (ScreenPtr pScrn
,
192 BoxPtr trackingArea
, INT16
*border
);
193 typedef Bool (*RRSetPanningProcPtr
) (ScreenPtr pScrn
,
196 BoxPtr trackingArea
, INT16
*border
);
198 #endif /* RANDR_13_INTERFACE */
200 typedef Bool (*RRGetInfoProcPtr
) (ScreenPtr pScreen
, Rotation
* rotations
);
201 typedef Bool (*RRCloseScreenProcPtr
) (int i
, ScreenPtr pscreen
);
203 /* These are for 1.0 compatibility */
205 typedef struct _rrRefresh
{
208 } RRScreenRate
, *RRScreenRatePtr
;
210 typedef struct _rrScreenSize
{
213 short mmWidth
, mmHeight
;
215 RRScreenRatePtr pRates
;
216 } RRScreenSize
, *RRScreenSizePtr
;
218 #ifdef RANDR_10_INTERFACE
220 typedef Bool (*RRSetConfigProcPtr
) (ScreenPtr pScreen
,
222 int rate
, RRScreenSizePtr pSize
);
226 typedef struct _rrScrPriv
{
228 * 'public' part of the structure; DDXen fill this in
231 #if RANDR_10_INTERFACE
232 RRSetConfigProcPtr rrSetConfig
;
234 RRGetInfoProcPtr rrGetInfo
;
235 #if RANDR_12_INTERFACE
236 RRScreenSetSizeProcPtr rrScreenSetSize
;
237 RRCrtcSetProcPtr rrCrtcSet
;
238 RRCrtcSetGammaProcPtr rrCrtcSetGamma
;
239 RRCrtcGetGammaProcPtr rrCrtcGetGamma
;
240 RROutputSetPropertyProcPtr rrOutputSetProperty
;
241 RROutputValidateModeProcPtr rrOutputValidateMode
;
242 RRModeDestroyProcPtr rrModeDestroy
;
244 #if RANDR_13_INTERFACE
245 RROutputGetPropertyProcPtr rrOutputGetProperty
;
246 RRGetPanningProcPtr rrGetPanning
;
247 RRSetPanningProcPtr rrSetPanning
;
251 * Private part of the structure; not considered part of the ABI
253 TimeStamp lastSetTime
; /* last changed by client */
254 TimeStamp lastConfigTime
; /* possible configs changed */
255 RRCloseScreenProcPtr CloseScreen
;
257 Bool changed
; /* some config changed */
258 Bool configChanged
; /* configuration changed */
259 Bool layoutChanged
; /* screen layout changed */
261 CARD16 minWidth
, minHeight
;
262 CARD16 maxWidth
, maxHeight
;
263 CARD16 width
, height
; /* last known screen size */
264 CARD16 mmWidth
, mmHeight
; /* last known screen size */
267 RROutputPtr
*outputs
;
268 RROutputPtr primaryOutput
;
273 /* Last known pointer position */
274 RRCrtcPtr pointerCrtc
;
276 #ifdef RANDR_10_INTERFACE
278 * Configuration information
281 CARD16 reqWidth
, reqHeight
;
284 RRScreenSizePtr pSizes
;
291 } rrScrPrivRec
, *rrScrPrivPtr
;
293 extern _X_EXPORT DevPrivateKeyRec rrPrivKeyRec
;
295 #define rrPrivKey (&rrPrivKeyRec)
297 #define rrGetScrPriv(pScr) ((rrScrPrivPtr)dixLookupPrivate(&(pScr)->devPrivates, rrPrivKey))
298 #define rrScrPriv(pScr) rrScrPrivPtr pScrPriv = rrGetScrPriv(pScr)
299 #define SetRRScreen(s,p) dixSetPrivate(&(s)->devPrivates, rrPrivKey, p)
302 * each window has a list of clients requesting
303 * RRNotify events. Each client has a resource
304 * for each window it selects RRNotify input for,
305 * this resource is used to delete the RRNotifyRec
306 * entry from the per-window queue.
309 typedef struct _RREvent
*RREventPtr
;
311 typedef struct _RREvent
{
319 typedef struct _RRTimes
{
321 TimeStamp configTime
;
322 } RRTimesRec
, *RRTimesPtr
;
324 typedef struct _RRClient
{
327 /* RRTimesRec times[0]; */
328 } RRClientRec
, *RRClientPtr
;
330 extern _X_EXPORT RESTYPE RRClientType
, RREventType
; /* resource types for event masks */
331 extern _X_EXPORT DevPrivateKeyRec RRClientPrivateKeyRec
;
333 #define RRClientPrivateKey (&RRClientPrivateKeyRec)
334 extern _X_EXPORT RESTYPE RRCrtcType
, RRModeType
, RROutputType
;
336 #define VERIFY_RR_OUTPUT(id, ptr, a)\
338 int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
339 RROutputType, client, a);\
340 if (rc != Success) {\
341 client->errorValue = id;\
346 #define VERIFY_RR_CRTC(id, ptr, a)\
348 int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
349 RRCrtcType, client, a);\
350 if (rc != Success) {\
351 client->errorValue = id;\
356 #define VERIFY_RR_MODE(id, ptr, a)\
358 int rc = dixLookupResourceByType((pointer *)&(ptr), id,\
359 RRModeType, client, a);\
360 if (rc != Success) {\
361 client->errorValue = id;\
366 #define GetRRClient(pClient) ((RRClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RRClientPrivateKey))
367 #define rrClientPriv(pClient) RRClientPtr pRRClient = GetRRClient(pClient)
369 /* Initialize the extension */
370 extern _X_EXPORT
void
371 RRExtensionInit(void);
373 #ifdef RANDR_12_INTERFACE
375 * Set the range of sizes for the screen
377 extern _X_EXPORT
void
379 RRScreenSetSizeRange(ScreenPtr pScreen
,
381 CARD16 minHeight
, CARD16 maxWidth
, CARD16 maxHeight
);
386 * Notify the extension that the screen size has been changed.
387 * The driver is responsible for calling this whenever it has changed
388 * the size of the screen
390 extern _X_EXPORT
void
391 RRScreenSizeNotify(ScreenPtr pScreen
);
394 * Request that the screen be resized
396 extern _X_EXPORT Bool
398 RRScreenSizeSet(ScreenPtr pScreen
,
399 CARD16 width
, CARD16 height
, CARD32 mmWidth
, CARD32 mmHeight
);
402 * Send ConfigureNotify event to root window when 'something' happens
404 extern _X_EXPORT
void
405 RRSendConfigNotify(ScreenPtr pScreen
);
411 ProcRRGetScreenSizeRange(ClientPtr client
);
414 ProcRRSetScreenSize(ClientPtr client
);
417 ProcRRGetScreenResources(ClientPtr client
);
420 ProcRRGetScreenResourcesCurrent(ClientPtr client
);
423 ProcRRSetScreenConfig(ClientPtr client
);
426 ProcRRGetScreenInfo(ClientPtr client
);
429 * Deliver a ScreenNotify event
431 extern _X_EXPORT
void
432 RRDeliverScreenEvent(ClientPtr client
, WindowPtr pWin
, ScreenPtr pScreen
);
436 * Send all pending events
438 extern _X_EXPORT
void
439 RRTellChanged(ScreenPtr pScreen
);
442 * Poll the driver for changed information
444 extern _X_EXPORT Bool
445 RRGetInfo(ScreenPtr pScreen
, Bool force_query
);
447 extern _X_EXPORT Bool
RRInit(void);
449 extern _X_EXPORT Bool
RRScreenInit(ScreenPtr pScreen
);
451 extern _X_EXPORT RROutputPtr
RRFirstOutput(ScreenPtr pScreen
);
453 extern _X_EXPORT CARD16
454 RRVerticalRefresh(xRRModeInfo
* mode
);
456 #ifdef RANDR_10_INTERFACE
458 * This is the old interface, deprecated but left
459 * around for compatibility
463 * Then, register the specific size with the screen
466 extern _X_EXPORT RRScreenSizePtr
467 RRRegisterSize(ScreenPtr pScreen
,
468 short width
, short height
, short mmWidth
, short mmHeight
);
470 extern _X_EXPORT Bool
471 RRRegisterRate(ScreenPtr pScreen
, RRScreenSizePtr pSize
, int rate
);
474 * Finally, set the current configuration of the screen
477 extern _X_EXPORT
void
479 RRSetCurrentConfig(ScreenPtr pScreen
,
480 Rotation rotation
, int rate
, RRScreenSizePtr pSize
);
482 extern _X_EXPORT Rotation
RRGetRotation(ScreenPtr pScreen
);
489 * Notify the CRTC of some change; layoutChanged indicates that
490 * some position or size element changed
492 extern _X_EXPORT
void
493 RRCrtcChanged(RRCrtcPtr crtc
, Bool layoutChanged
);
498 extern _X_EXPORT RRCrtcPtr
RRCrtcCreate(ScreenPtr pScreen
, void *devPrivate
);
501 * Set the allowed rotations on a CRTC
503 extern _X_EXPORT
void
504 RRCrtcSetRotations(RRCrtcPtr crtc
, Rotation rotations
);
507 * Set whether transforms are allowed on a CRTC
509 extern _X_EXPORT
void
510 RRCrtcSetTransformSupport(RRCrtcPtr crtc
, Bool transforms
);
513 * Notify the extension that the Crtc has been reconfigured,
514 * the driver calls this whenever it has updated the mode
516 extern _X_EXPORT Bool
518 RRCrtcNotify(RRCrtcPtr crtc
,
523 RRTransformPtr transform
, int numOutputs
, RROutputPtr
* outputs
);
525 extern _X_EXPORT
void
526 RRDeliverCrtcEvent(ClientPtr client
, WindowPtr pWin
, RRCrtcPtr crtc
);
529 * Request that the Crtc be reconfigured
531 extern _X_EXPORT Bool
533 RRCrtcSet(RRCrtcPtr crtc
,
536 int y
, Rotation rotation
, int numOutput
, RROutputPtr
* outputs
);
539 * Request that the Crtc gamma be changed
542 extern _X_EXPORT Bool
543 RRCrtcGammaSet(RRCrtcPtr crtc
, CARD16
*red
, CARD16
*green
, CARD16
*blue
);
546 * Request current gamma back from the DDX (if possible).
547 * This includes gamma size.
550 extern _X_EXPORT Bool
551 RRCrtcGammaGet(RRCrtcPtr crtc
);
554 * Notify the extension that the Crtc gamma has been changed
555 * The driver calls this whenever it has changed the gamma values
559 extern _X_EXPORT Bool
560 RRCrtcGammaNotify(RRCrtcPtr crtc
);
563 * Set the size of the gamma table at server startup time
566 extern _X_EXPORT Bool
567 RRCrtcGammaSetSize(RRCrtcPtr crtc
, int size
);
570 * Return the area of the frame buffer scanned out by the crtc,
571 * taking into account the current mode and rotation
574 extern _X_EXPORT
void
575 RRCrtcGetScanoutSize(RRCrtcPtr crtc
, int *width
, int *height
);
578 * Compute the complete transformation matrix including
579 * client-specified transform, rotation/reflection values and the crtc
582 * Return TRUE if the resulting transform is not a simple translation.
584 extern _X_EXPORT Bool
586 RRTransformCompute(int x
,
591 RRTransformPtr rr_transform
,
592 PictTransformPtr transform
,
593 struct pict_f_transform
*f_transform
,
594 struct pict_f_transform
*f_inverse
);
597 * Return crtc transform
599 extern _X_EXPORT RRTransformPtr
RRCrtcGetTransform(RRCrtcPtr crtc
);
602 * Check whether the pending and current transforms are the same
604 extern _X_EXPORT Bool
605 RRCrtcPendingTransform(RRCrtcPtr crtc
);
608 * Destroy a Crtc at shutdown
610 extern _X_EXPORT
void
611 RRCrtcDestroy(RRCrtcPtr crtc
);
614 * Set the pending CRTC transformation
619 RRCrtcTransformSet(RRCrtcPtr crtc
,
620 PictTransformPtr transform
,
621 struct pict_f_transform
*f_transform
,
622 struct pict_f_transform
*f_inverse
,
623 char *filter
, int filter_len
, xFixed
* params
, int nparams
);
626 * Initialize crtc type
628 extern _X_EXPORT Bool
632 * Initialize crtc type error value
634 extern _X_EXPORT
void
635 RRCrtcInitErrorValue(void);
642 ProcRRGetCrtcInfo(ClientPtr client
);
645 ProcRRSetCrtcConfig(ClientPtr client
);
648 ProcRRGetCrtcGammaSize(ClientPtr client
);
651 ProcRRGetCrtcGamma(ClientPtr client
);
654 ProcRRSetCrtcGamma(ClientPtr client
);
657 ProcRRSetCrtcTransform(ClientPtr client
);
660 ProcRRGetCrtcTransform(ClientPtr client
);
663 ProcRRGetPanning(ClientPtr client
);
666 ProcRRSetPanning(ClientPtr client
);
669 RRConstrainCursorHarder(DeviceIntPtr
, ScreenPtr
, int, int *, int *);
672 extern _X_EXPORT Bool
673 RRClientKnowsRates(ClientPtr pClient
);
677 * Find, and if necessary, create a mode
680 extern _X_EXPORT RRModePtr
RRModeGet(xRRModeInfo
* modeInfo
, const char *name
);
686 extern _X_EXPORT
void
687 RRModeDestroy(RRModePtr mode
);
690 * Return a list of modes that are valid for some output in pScreen
692 extern _X_EXPORT RRModePtr
*RRModesForScreen(ScreenPtr pScreen
, int *num_ret
);
695 * Initialize mode type
697 extern _X_EXPORT Bool
701 * Initialize mode type error value
703 extern _X_EXPORT
void
704 RRModeInitErrorValue(void);
707 ProcRRCreateMode(ClientPtr client
);
710 ProcRRDestroyMode(ClientPtr client
);
713 ProcRRAddOutputMode(ClientPtr client
);
716 ProcRRDeleteOutputMode(ClientPtr client
);
721 * Notify the output of some change. configChanged indicates whether
722 * any external configuration (mode list, clones, connected status)
723 * has changed, or whether the change was strictly internal
724 * (which crtc is in use)
726 extern _X_EXPORT
void
727 RROutputChanged(RROutputPtr output
, Bool configChanged
);
733 extern _X_EXPORT RROutputPtr
734 RROutputCreate(ScreenPtr pScreen
,
735 const char *name
, int nameLength
, void *devPrivate
);
738 * Notify extension that output parameters have been changed
740 extern _X_EXPORT Bool
741 RROutputSetClones(RROutputPtr output
, RROutputPtr
* clones
, int numClones
);
743 extern _X_EXPORT Bool
745 RROutputSetModes(RROutputPtr output
,
746 RRModePtr
* modes
, int numModes
, int numPreferred
);
749 RROutputAddUserMode(RROutputPtr output
, RRModePtr mode
);
752 RROutputDeleteUserMode(RROutputPtr output
, RRModePtr mode
);
754 extern _X_EXPORT Bool
755 RROutputSetCrtcs(RROutputPtr output
, RRCrtcPtr
* crtcs
, int numCrtcs
);
757 extern _X_EXPORT Bool
758 RROutputSetConnection(RROutputPtr output
, CARD8 connection
);
760 extern _X_EXPORT Bool
761 RROutputSetSubpixelOrder(RROutputPtr output
, int subpixelOrder
);
763 extern _X_EXPORT Bool
764 RROutputSetPhysicalSize(RROutputPtr output
, int mmWidth
, int mmHeight
);
766 extern _X_EXPORT
void
767 RRDeliverOutputEvent(ClientPtr client
, WindowPtr pWin
, RROutputPtr output
);
769 extern _X_EXPORT
void
770 RROutputDestroy(RROutputPtr output
);
773 ProcRRGetOutputInfo(ClientPtr client
);
776 ProcRRSetOutputPrimary(ClientPtr client
);
779 ProcRRGetOutputPrimary(ClientPtr client
);
782 * Initialize output type
784 extern _X_EXPORT Bool
788 * Initialize output type error value
790 extern _X_EXPORT
void
791 RROutputInitErrorValue(void);
794 extern _X_EXPORT
void
795 RRPointerMoved(ScreenPtr pScreen
, int x
, int y
);
797 extern _X_EXPORT
void
798 RRPointerScreenConfigured(ScreenPtr pScreen
);
802 extern _X_EXPORT
void
803 RRDeleteAllOutputProperties(RROutputPtr output
);
805 extern _X_EXPORT RRPropertyValuePtr
806 RRGetOutputProperty(RROutputPtr output
, Atom property
, Bool pending
);
808 extern _X_EXPORT RRPropertyPtr
809 RRQueryOutputProperty(RROutputPtr output
, Atom property
);
811 extern _X_EXPORT
void
812 RRDeleteOutputProperty(RROutputPtr output
, Atom property
);
814 extern _X_EXPORT Bool
815 RRPostPendingProperties(RROutputPtr output
);
819 RRChangeOutputProperty(RROutputPtr output
, Atom property
, Atom type
,
820 int format
, int mode
, unsigned long len
,
821 pointer value
, Bool sendevent
, Bool pending
);
825 RRConfigureOutputProperty(RROutputPtr output
, Atom property
,
826 Bool pending
, Bool range
, Bool immutable
,
827 int num_values
, INT32
*values
);
829 ProcRRChangeOutputProperty(ClientPtr client
);
832 ProcRRGetOutputProperty(ClientPtr client
);
835 ProcRRListOutputProperties(ClientPtr client
);
838 ProcRRQueryOutputProperty(ClientPtr client
);
841 ProcRRConfigureOutputProperty(ClientPtr client
);
844 ProcRRDeleteOutputProperty(ClientPtr client
);
848 extern _X_EXPORT
void
849 RRXineramaExtensionInit(void);
852 #endif /* _RANDRSTR_H_ */
856 randr extension implementation structure
859 ProcRRGetScreenInfo/ProcRRGetScreenResources
862 • Request configuration from driver, either 1.0 or 1.2 style
863 • These functions only record state changes, all
864 other actions are pended until RRTellChanged is called
876 RROutputSetConnection
877 RROutputSetSubpixelOrder
881 • Must delay scanning configuration until after ->rrGetInfo returns
882 because some drivers will call SetCurrentConfig in the middle
883 of the ->rrGetInfo operation.
887 • Scan old configuration, mirror to new structures
893 RROutputSetConnection
894 RROutputSetSubpixelOrder
895 RROldModeAdd • This adds modes one-at-a-time
899 • send events, reset pointer if necessary
902 WalkTree (sending events)
904 • when layout has changed:
905 RRPointerScreenConfigured
908 Asynchronous state setting (1.2 only)
909 When setting state asynchronously, the driver invokes the
910 ->rrGetInfo function and then calls RRTellChanged to flush
911 the changes to the clients and reset pointer if necessary
915 ProcRRSetScreenConfig