summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@neko.keithp.com>2006-09-16 23:21:37 -0700
committerKeith Packard <keithp@neko.keithp.com>2006-09-17 23:08:12 -0700
commit3e745745fecef1cb59e53bde52ded311b51e1dac (patch)
treeb407f48fe1cb2841c3dfe0d0530936801427ea06
parentd17fb9672e238a089e463ac74cc4cd3325b67e1f (diff)
Split RandR implementation into separate files.
RandR is getting too big to live in one file; split into one file per object type (crtc, mode, screen), leaving the rest of the code in randr.c. Code is slowly approaching the point where it will drop-in as a replacement for the old 1.0 implementation.
-rw-r--r--randr/Makefile.am6
-rw-r--r--randr/mirandr.c7
-rw-r--r--randr/randr.c419
-rw-r--r--randr/randrstr.h273
-rw-r--r--randr/rrcrtc.c238
-rw-r--r--randr/rrmode.c85
-rw-r--r--randr/rroutput.c56
-rw-r--r--randr/rrscreen.c205
8 files changed, 852 insertions, 437 deletions
diff --git a/randr/Makefile.am b/randr/Makefile.am
index bd30aed8a..868786ecb 100644
--- a/randr/Makefile.am
+++ b/randr/Makefile.am
@@ -9,4 +9,8 @@ endif
librandr_la_SOURCES = \
mirandr.c \
randr.c \
- randrstr.h
+ randrstr.h \
+ rrcrtc.c \
+ rrmode.c \
+ rroutput.c \
+ rrscreen.c
diff --git a/randr/mirandr.c b/randr/mirandr.c
index 5aea38d60..a57a157ca 100644
--- a/randr/mirandr.c
+++ b/randr/mirandr.c
@@ -70,16 +70,19 @@ Bool
miRandRInit (ScreenPtr pScreen)
{
rrScrPrivPtr pScrPriv;
+#if RANDR_12_INTERFACE
RRModePtr mode;
RRCrtcPtr crtc;
RROutputPtr output;
xRRModeInfo modeInfo;
char name[64];
+#endif
if (!RRScreenInit (pScreen))
return FALSE;
pScrPriv = rrGetScrPriv(pScreen);
pScrPriv->rrGetInfo = miRRGetInfo;
+#if RANDR_12_INTERFACE
pScrPriv->rrCrtcSet = miRRCrtcSet;
RRScreenSetSizeRange (pScreen,
@@ -111,7 +114,7 @@ miRandRInit (ScreenPtr pScreen)
&crtc, 1, /* crtcs */
RR_Connected))
return FALSE;
- if (!RRCrtcSet (crtc, mode, 0, 0, RR_Rotate_0, 1, &output))
- return FALSE;
+ RRCrtcNotify (crtc, mode, 0, 0, RR_Rotate_0, 1, &output);
+#endif
return TRUE;
}
diff --git a/randr/randr.c b/randr/randr.c
index e34b82c2f..2305b6094 100644
--- a/randr/randr.c
+++ b/randr/randr.c
@@ -31,25 +31,7 @@
#include <dix-config.h>
#endif
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "os.h"
-#include "dixstruct.h"
-#include "resource.h"
-#include "scrnintstr.h"
-#include "windowstr.h"
-#include "pixmapstr.h"
-#include "extnsionst.h"
-#include "servermd.h"
-#include <X11/extensions/randr.h>
-#include <X11/extensions/randrproto.h>
#include "randrstr.h"
-#ifdef RENDER
-#include <X11/extensions/render.h> /* we share subpixel order information */
-#include "picturestr.h"
-#endif
-#include <X11/Xfuncproto.h>
/* From render.h */
#ifndef SubPixelUnknown
@@ -60,8 +42,6 @@
int RRGeneration;
int RRNScreens;
-static RESTYPE ModeType, CrtcType, OutputType;
-
static int ProcRRQueryVersion (ClientPtr pClient);
static int ProcRRDispatch (ClientPtr pClient);
static int SProcRRDispatch (ClientPtr pClient);
@@ -80,7 +60,7 @@ static int SProcRRQueryVersion (ClientPtr pClient);
static CARD8 RRReqCode;
static int RRErrBase;
#endif
-static int RREventBase;
+int RREventBase;
static RESTYPE ClientType, EventType; /* resource types for event masks */
static int RRClientPrivateIndex;
@@ -233,50 +213,21 @@ SRRNotifyEvent (xEvent *from,
}
}
-static int
-RRModeDestroyResource (pointer value, XID pid)
-{
- RRModeDestroy ((RRModePtr) value);
- return 1;
-}
-
-static int
-RRCrtcDestroyResource (pointer value, XID pid)
-{
- RRCrtcDestroy ((RRCrtcPtr) value);
- return 1;
-}
-
-static int
-RROutputDestroyResource (pointer value, XID pid)
-{
- RROutputDestroy ((RROutputPtr) value);
- return 1;
-}
-
Bool RRScreenInit(ScreenPtr pScreen)
{
rrScrPrivPtr pScrPriv;
if (RRGeneration != serverGeneration)
{
- ModeType = CreateNewResourceType (RRModeDestroyResource);
- if (!ModeType)
+ if (!RRModeInit ())
return FALSE;
- CrtcType = CreateNewResourceType (RRCrtcDestroyResource);
- if (!ModeType)
+ if (!RRCrtcInit ())
return FALSE;
- OutputType = CreateNewResourceType (RROutputDestroyResource);
- if (!ModeType)
+ if (!RROutputInit ())
return FALSE;
if ((rrPrivIndex = AllocateScreenPrivateIndex()) < 0)
return FALSE;
RRGeneration = serverGeneration;
-#ifdef XResExtension
- RegisterResourceName (ModeType, "MODE");
- RegisterResourceName (CrtcType, "CRTC");
- RegisterResourceName (OutputType, "OUTPUT");
-#endif
}
pScrPriv = (rrScrPrivPtr) xalloc (sizeof (rrScrPrivRec));
@@ -288,14 +239,23 @@ Bool RRScreenInit(ScreenPtr pScreen)
/*
* Calling function best set these function vectors
*/
- pScrPriv->rrCrtcSet = 0;
pScrPriv->rrGetInfo = 0;
pScrPriv->maxWidth = pScrPriv->minWidth = pScreen->width;
pScrPriv->maxHeight = pScrPriv->minHeight = pScreen->height;
-#ifdef RANDR_SCREEN_INTERFACE
+
+#if RANDR_12_INTERFACE
+ pScrPriv->rrCrtcSet = 0;
+#endif
+#if RANDR_10_INTERFACE
pScrPriv->rrSetConfig = 0;
+ pScrPriv->rotations = RR_Rotate_0;
pScrPriv->reqWidth = pScreen->width;
pScrPriv->reqHeight = pScreen->height;
+ pScrPriv->nSizes = 0;
+ pScrPriv->pSizes = NULL;
+ pScrPriv->rotation = RR_Rotate_0;
+ pScrPriv->rate = 0;
+ pScrPriv->size = 0;
#endif
/*
@@ -400,61 +360,6 @@ RRExtensionInit (void)
return;
}
-
-static void
-DeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen)
-{
- rrScrPriv (pScreen);
- xRRScreenChangeNotifyEvent se;
- RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL;
- RROutputPtr output = pScrPriv->numOutputs ? pScrPriv->outputs[0] : NULL;
- RRModePtr mode = crtc ? crtc->mode : NULL;
- WindowPtr pRoot = WindowTable[pScreen->myNum];
- int i;
-
- se.type = RRScreenChangeNotify + RREventBase;
- se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0);
- se.timestamp = pScrPriv->lastSetTime.milliseconds;
- se.sequenceNumber = client->sequence;
- se.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
- se.root = pRoot->drawable.id;
- se.window = pWin->drawable.id;
-#ifdef RENDER
- se.subpixelOrder = PictureGetSubpixelOrder (pScreen);
-#else
- se.subpixelOrder = SubPixelUnknown;
-#endif
-
- se.sequenceNumber = client->sequence;
- if (mode)
- {
- se.sizeID = -1;
- for (i = 0; i < output->numModes; i++)
- if (mode == output->modes[i])
- {
- se.sizeID = i;
- break;
- }
- se.widthInPixels = mode->mode.width;
- se.heightInPixels = mode->mode.height;
- se.widthInMillimeters = mode->mode.mmWidth;
- se.heightInMillimeters = mode->mode.mmHeight;
- }
- else
- {
- /*
- * This "shouldn't happen", but a broken DDX can
- * forget to set the current configuration on GetInfo
- */
- se.sizeID = 0xffff;
- se.widthInPixels = 0;
- se.heightInPixels = 0;
- se.widthInMillimeters = 0;
- se.heightInMillimeters = 0;
- }
- WriteEventsToClient (client, 1, (xEvent *) &se);
-}
-
static void
DeliverCrtcEvent (ClientPtr client, WindowPtr pWin, RRCrtcPtr crtc)
{
@@ -485,7 +390,7 @@ TellChanged (WindowPtr pWin, pointer value)
continue;
if (pRREvent->mask & RRScreenChangeNotifyMask)
- DeliverScreenEvent (client, pWin, pScreen);
+ RRDeliverScreenEvent (client, pWin, pScreen);
if (pRREvent->mask & RRCrtcChangeNotifyMask)
{
@@ -529,47 +434,6 @@ RRTellChanged (ScreenPtr pScreen)
}
}
-RRModePtr
-RRModeGet (ScreenPtr pScreen,
- xRRModeInfo *modeInfo,
- char *name)
-{
- rrScrPriv (pScreen);
- int i;
- RRModePtr mode;
-
- for (i = 0; i < pScrPriv->numModes; i++)
- {
- mode = pScrPriv->modes[i];
- if (!memcmp (modeInfo, &mode->mode, sizeof (xRRModeInfo)) &&
- !memcmp (name, mode->name, modeInfo->nameLength))
- {
- ++mode->refcnt;
- return mode;
- }
- }
- mode = xalloc (sizeof (RRModeRec) + modeInfo->nameLength + 1);
- mode->refcnt = 1;
- mode->mode = *modeInfo;
- mode->name = (char *) (mode + 1);
- memcpy (mode->name, name, modeInfo->nameLength);
- mode->name[modeInfo->nameLength] = '\0';
- mode->id = FakeClientID(0);
- if (!AddResource (mode->id, ModeType, (pointer) mode))
- return NULL;
- ++mode->refcnt;
- pScrPriv->changed = TRUE;
- return mode;
-}
-
-void
-RRModeDestroy (RRModePtr mode)
-{
- if (--mode->refcnt > 0)
- return;
- xfree (mode);
-}
-
/*
* Return the first output which is connected to an active CRTC
* Used in emulating 1.0 behaviour
@@ -594,11 +458,13 @@ RRFirstOutput (ScreenPtr pScreen)
return NULL;
}
-#ifdef RANDR_SCREEN_INTERFACE
+#ifdef RANDR_10_INTERFACE
-static Bool
+static RRModePtr
RROldModeAdd (RROutputPtr output, RRScreenSizePtr size, int refresh)
{
+ ScreenPtr pScreen = output->pScreen;
+ rrScrPriv(pScreen);
xRRModeInfo modeInfo;
char name[100];
RRModePtr mode;
@@ -617,12 +483,15 @@ RROldModeAdd (RROutputPtr output, RRScreenSizePtr size, int refresh)
modeInfo.dotClock = ((CARD32) size->width * (CARD32) size->width *
(CARD32) refresh);
modeInfo.nameLength = strlen (name);
- mode = RRModeGet (output->pScreen, &modeInfo, name);
+ mode = RRModeGet (pScreen, &modeInfo, name);
if (!mode)
- return FALSE;
+ return NULL;
for (i = 0; i < output->numModes; i++)
if (output->modes[i] == mode)
- return TRUE;
+ {
+ RRModeDestroy (mode);
+ return mode;
+ }
if (output->numModes)
modes = xrealloc (output->modes,
@@ -630,11 +499,16 @@ RROldModeAdd (RROutputPtr output, RRScreenSizePtr size, int refresh)
else
modes = xalloc (sizeof (RRModePtr));
if (!modes)
- return FALSE;
+ {
+ RRModeDestroy (mode);
+ FreeResource (mode->id, 0);
+ return NULL;
+ }
modes[output->numModes++] = mode;
output->modes = modes;
output->changed = TRUE;
- return TRUE;
+ pScrPriv->changed = TRUE;
+ return mode;
}
static void
@@ -643,6 +517,7 @@ RRScanOldConfig (ScreenPtr pScreen, Rotation rotations)
rrScrPriv(pScreen);
RROutputPtr output = RRFirstOutput (pScreen);
RRCrtcPtr crtc;
+ RRModePtr mode, newMode = NULL;
int i;
CARD16 minWidth = MAXSHORT, minHeight = MAXSHORT;
CARD16 maxWidth = 0, maxHeight = 0;
@@ -666,11 +541,29 @@ RRScanOldConfig (ScreenPtr pScreen, Rotation rotations)
int r;
if (size->nRates)
+ {
for (r = 0; r < size->nRates; r++)
- RROldModeAdd (output, size, size->pRates[r].rate);
+ {
+ mode = RROldModeAdd (output, size, size->pRates[r].rate);
+ if (i == pScrPriv->size &&
+ size->pRates[r].rate == pScrPriv->rate)
+ {
+ newMode = mode;
+ }
+ }
+ xfree (size->pRates);
+ }
else
- RROldModeAdd (output, size, 0);
+ {
+ mode = RROldModeAdd (output, size, 0);
+ if (i == pScrPriv->size)
+ newMode = mode;
+ }
}
+ if (pScrPriv->nSizes)
+ xfree (pScrPriv->pSizes);
+ pScrPriv->pSizes = NULL;
+ pScrPriv->nSizes = 0;
/* find size bounds */
for (i = 0; i < output->numModes; i++)
@@ -697,9 +590,17 @@ RRScanOldConfig (ScreenPtr pScreen, Rotation rotations)
if (maxHeight != pScrPriv->maxHeight) {
pScrPriv->maxHeight = maxHeight; pScrPriv->changed = TRUE;
}
+
+ /* notice current mode */
+ if (newMode)
+ RRCrtcSet (output->crtc, newMode, 0, 0, pScrPriv->rotation,
+ 1, &output);
}
#endif
+/*
+ * Poll the driver for changed information
+ */
static Bool
RRGetInfo (ScreenPtr pScreen)
{
@@ -718,7 +619,7 @@ RRGetInfo (ScreenPtr pScreen)
if (!(*pScrPriv->rrGetInfo) (pScreen, &rotations))
return FALSE;
-#if RANDR_SCREEN_INTERFACE
+#if RANDR_10_INTERFACE
if (pScrPriv->nSizes)
RRScanOldConfig (pScreen, rotations);
#endif
@@ -726,27 +627,6 @@ RRGetInfo (ScreenPtr pScreen)
return TRUE;
}
-static void
-RRSendConfigNotify (ScreenPtr pScreen)
-{
- WindowPtr pWin = WindowTable[pScreen->myNum];
- xEvent event;
-
- event.u.u.type = ConfigureNotify;
- event.u.configureNotify.window = pWin->drawable.id;
- event.u.configureNotify.aboveSibling = None;
- event.u.configureNotify.x = 0;
- event.u.configureNotify.y = 0;
-
- /* XXX xinerama stuff ? */
-
- event.u.configureNotify.width = pWin->drawable.width;
- event.u.configureNotify.height = pWin->drawable.height;
- event.u.configureNotify.borderWidth = wBorderWidth (pWin);
- event.u.configureNotify.override = pWin->overrideRedirect;
- DeliverEvents(pWin, &event, 1, NullWindow);
-}
-
static int
ProcRRQueryVersion (ClientPtr client)
{
@@ -777,50 +657,6 @@ ProcRRQueryVersion (ClientPtr client)
return (client->noClientException);
}
-
-extern char *ConnectionInfo;
-
-static int padlength[4] = {0, 3, 2, 1};
-
-static void
-RREditConnectionInfo (ScreenPtr pScreen)
-{
- xConnSetup *connSetup;
- char *vendor;
- xPixmapFormat *formats;
- xWindowRoot *root;
- xDepth *depth;
- xVisualType *visual;
- int screen = 0;
- int d;
-
- connSetup = (xConnSetup *) ConnectionInfo;
- vendor = (char *) connSetup + sizeof (xConnSetup);
- formats = (xPixmapFormat *) ((char *) vendor +
- connSetup->nbytesVendor +
- padlength[connSetup->nbytesVendor & 3]);
- root = (xWindowRoot *) ((char *) formats +
- sizeof (xPixmapFormat) * screenInfo.numPixmapFormats);
- while (screen != pScreen->myNum)
- {
- depth = (xDepth *) ((char *) root +
- sizeof (xWindowRoot));
- for (d = 0; d < root->nDepths; d++)
- {
- visual = (xVisualType *) ((char *) depth +
- sizeof (xDepth));
- depth = (xDepth *) ((char *) visual +
- depth->nVisuals * sizeof (xVisualType));
- }
- root = (xWindowRoot *) ((char *) depth);
- screen++;
- }
- root->pixWidth = pScreen->width;
- root->pixHeight = pScreen->height;
- root->mmWidth = pScreen->mmWidth;
- root->mmHeight = pScreen->mmHeight;
-}
-
typedef struct _RR10Data {
RRScreenSizePtr sizes;
int nsize;
@@ -829,7 +665,7 @@ typedef struct _RR10Data {
CARD16 refresh;
} RR10DataRec, *RR10DataPtr;
-static CARD16
+CARD16
RRVerticalRefresh (xRRModeInfo *mode)
{
CARD32 refresh;
@@ -1056,94 +892,6 @@ ProcRRGetScreenInfo (ClientPtr client)
}
#if 0
-static int
-RRMonitorSetMode (ScreenPtr pScreen, RRMonitorPtr pMonitor,
- RRModePtr pMode, int x, int y, Rotation rotation,
- TimeStamp time)
-{
- rrScrPriv(pScreen);
- short oldWidth, oldHeight;
-
- oldWidth = pScreen->width;
- oldHeight = pScreen->height;
-
- /*
- * call out to ddx routine to effect the change
- */
- if (pScrPriv->rrSetScreenSize && pScrPriv->rrSetMode)
- {
- xScreenSizes oldSize;
- if (!(*pScrPriv->rrSetMode) (pScreen, 0, NULL, 0, 0, RR_Rotate_0))
- return RRSetConfigFailed;
- oldSize.widthInPixels = pScreen->width;
- oldSize.heightInPixels = pScreen->width;
- oldSize.widthInMillimeters = pScreen->mmWidth;
- oldSize.heightInMillimeters = pScreen->mmHeight;
- if (!(*pScrPriv->rrSetScreenSize) (pScreen,
- pMode->mode.width,
- pMode->mode.height,
- pMode->mode.widthInMillimeters,
- pMode->mode.heightInMillimeters))
- {
- (void) (*pScrPriv->rrSetMode) (pScreen, 0, pMonitor->pMode,
- pMonitor->x, pMonitor->y,
- pMonitor->rotation);
- return RRSetConfigFailed;
- }
- if (!(*pScrPriv->rrSetMode) (pScreen, 0, pMode, 0, 0, rotation))
- {
- (void) (*pScrPriv->rrSetScreenSize) (pScreen,
- oldSize.widthInPixels,
- oldSize.heightInPixels,
- oldSize.widthInMillimeters,
- oldSize.heightInMillimeters);
- (void) (*pScrPriv->rrSetMode) (pScreen, 0, pMonitor->pMode,
- pMonitor->x, pMonitor->y,
- pMonitor->rotation);
- return RRSetConfigFailed;
- }
- }
-#ifdef RANDR_SCREEN_INTERFACE
- else if (pScrPriv->rrSetConfig)
- {
- int rate = RRVerticalRefresh (&pMode->mode);
- RRScreenSizeRec size;
-
- size.width = pMode->mode.width;
- size.height = pMode->mode.height;
- size.mmWidth = pMode->mode.widthInMillimeters;
- size.mmHeight = pMode->mode.heightInMillimeters;
- if (!(*pScrPriv->rrSetConfig) (pScreen, rotation, rate, &size))
- return RRSetConfigFailed;
- }
-#endif
- else
- return RRSetConfigFailed;
-
- /*
- * set current extension configuration pointers
- */
- RRSetCurrentMode (pMonitor, pMode, 0, 0, rotation);
-
- /*
- * Deliver ScreenChangeNotify events whenever
- * the configuration is updated
- */
- WalkTree (pScreen, TellChanged, (pointer) pScreen);
-
- /*
- * Deliver ConfigureNotify events when root changes
- * pixel size
- */
- if (oldWidth != pScreen->width || oldHeight != pScreen->height)
- RRSendConfigNotify (pScreen);
- RREditConnectionInfo (pScreen);
-
- /*
- * Fix pointer bounds and location
- */
- ScreenRestructured (pScreen);
- pScrPriv->lastSetTime = time;
return RRSetConfigSuccess;
}
#endif
@@ -1411,36 +1159,6 @@ RRSetScreenConfig (ScreenPtr pScreen,
}
#endif
-static Bool
-RRSetScreenSize (ScreenPtr pScreen,
- CARD16 width, CARD16 height,
- CARD16 widthInMillimeters, CARD16 heightInMillimeters)
-{
- rrScrPriv(pScreen);
-
- if (pScrPriv->rrScreenSetSize)
- {
- return (*pScrPriv->rrScreenSetSize) (pScreen, width, height,
- widthInMillimeters,
- heightInMillimeters);
- }
-#ifdef RANDR_SCREEN_INTERFACE
- else
- {
- /* Pend the size change until we get the set mode request.
- * Yes, this is 'illegal', but the best we can do until
- * drivers are updated
- */
- pScrPriv->reqWidth = width;
- pScrPriv->reqHeight = height;
- pScreen->mmWidth = widthInMillimeters;
- pScreen->mmHeight = heightInMillimeters;
- return TRUE;
- }
-#endif
- return FALSE;
-}
-
static int
ProcRRSelectInput (ClientPtr client)
{
@@ -1524,7 +1242,7 @@ ProcRRSelectInput (ClientPtr client)
CompareTimeStamps (pTimes->configTime,
pScrPriv->lastConfigTime) != 0)
{
- DeliverScreenEvent (client, pWin, pScreen);
+ RRDeliverScreenEvent (client, pWin, pScreen);
}
}
}
@@ -1651,7 +1369,7 @@ static int ProcRRSetScreenSize (ClientPtr client)
client->errorValue = 0;
return BadValue;
}
- if (!RRSetScreenSize (pScreen,
+ if (!RRScreenSizeSet (pScreen,
stuff->width, stuff->height,
stuff->widthInMillimeters,
stuff->heightInMillimeters))
@@ -2000,6 +1718,7 @@ SProcRRDispatch (ClientPtr client)
}
}
+#if RANDR_12_INTERFACE
/*
* Register the range of sizes for the screen
*/
@@ -2019,8 +1738,9 @@ RRScreenSetSizeRange (ScreenPtr pScreen,
pScrPriv->maxWidth = maxWidth;
pScrPriv->maxHeight = maxHeight;
}
+#endif
-#ifdef RANDR_SCREEN_INTERFACE
+#ifdef RANDR_10_INTERFACE
static Bool
RRScreenSizeMatches (RRScreenSizePtr a,
@@ -2052,6 +1772,7 @@ RRRegisterSize (ScreenPtr pScreen,
if (!pScrPriv)
return 0;
+ tmp.id = 0;
tmp.width = width;
tmp.height= height;
tmp.mmWidth = mmWidth;
diff --git a/randr/randrstr.h b/randr/randrstr.h
index 16945231a..f323660d9 100644
--- a/randr/randrstr.h
+++ b/randr/randrstr.h
@@ -32,15 +32,35 @@
#ifndef _RANDRSTR_H_
#define _RANDRSTR_H_
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "misc.h"
+#include "os.h"
+#include "dixstruct.h"
+#include "resource.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+#include "pixmapstr.h"
+#include "extnsionst.h"
+#include "servermd.h"
+#include <X11/extensions/randr.h>
#include <X11/extensions/randrproto.h>
+#ifdef RENDER
+#include <X11/extensions/render.h> /* we share subpixel order information */
+#include "picturestr.h"
+#endif
+#include <X11/Xfuncproto.h>
/* required for ABI compatibility for now */
-#define RANDR_SCREEN_INTERFACE 1
+#define RANDR_10_INTERFACE 1
+/* #define RANDR_12_INTERFACE 1 */
typedef XID RRMode;
typedef XID RROutput;
typedef XID RRCrtc;
+extern int RREventBase;
+
/*
* Modeline for a monitor. Name follows directly after this struct
*/
@@ -64,9 +84,9 @@ struct _rrCrtc {
int x, y;
Rotation rotation;
Rotation rotations;
- int numPossibleOutputs;
- RROutputPtr *possibleOutputs;
Bool changed;
+ int numOutputs;
+ RROutputPtr *outputs;
void *devPrivate;
};
@@ -88,11 +108,12 @@ struct _rrOutput {
void *devPrivate;
};
-typedef Bool (*RRScreenSetSizeProcPtr) (ScreenPtr pScreen,
+#if RANDR_12_INTERFACE
+typedef Bool (*RRScreentSizeSetProcPtr) (ScreenPtr pScreen,
CARD16 width,
CARD16 height,
- CARD32 widthInMM,
- CARD32 heightInMM);
+ CARD32 mmWidth,
+ CARD32 mmHeight);
typedef Bool (*RRCrtcSetProcPtr) (ScreenPtr pScreen,
RRCrtcPtr crtc,
@@ -100,8 +121,9 @@ typedef Bool (*RRCrtcSetProcPtr) (ScreenPtr pScreen,
int x,
int y,
Rotation rotation,
- int numOutput,
+ int numOutputs,
RROutputPtr *outputs);
+#endif
typedef Bool (*RRGetInfoProcPtr) (ScreenPtr pScreen, Rotation *rotations);
typedef Bool (*RRCloseScreenProcPtr) ( int i, ScreenPtr pscreen);
@@ -121,7 +143,7 @@ typedef struct _rrScreenSize {
RRScreenRatePtr pRates;
} RRScreenSize, *RRScreenSizePtr;
-#ifdef RANDR_SCREEN_INTERFACE
+#ifdef RANDR_10_INTERFACE
typedef Bool (*RRSetConfigProcPtr) (ScreenPtr pScreen,
Rotation rotation,
@@ -136,12 +158,14 @@ typedef struct _rrScrPriv {
* 'public' part of the structure; DDXen fill this in
* as they initialize
*/
-#ifdef RANDR_SCREEN_INTERFACE
+#if RANDR_10_INTERFACE
RRSetConfigProcPtr rrSetConfig;
#endif
RRGetInfoProcPtr rrGetInfo;
- RRScreenSetSizeProcPtr rrScreenSetSize;
+#if RANDR_12_INTERFACE
+ RRScreenSetSizeProcPtr rrScreenSizeSet;
RRCrtcSetProcPtr rrCrtcSet;
+#endif
/*
* Private part of the structure; not considered part of the ABI
@@ -152,6 +176,7 @@ typedef struct _rrScrPriv {
Bool changed;
CARD16 minWidth, minHeight;
CARD16 maxWidth, maxHeight;
+ CARD16 width, height; /* last known screen size */
/* modes, outputs and crtcs */
int numModes;
@@ -163,7 +188,7 @@ typedef struct _rrScrPriv {
int numCrtcs;
RRCrtcPtr *crtcs;
-#ifdef RANDR_SCREEN_INTERFACE
+#ifdef RANDR_10_INTERFACE
/*
* Configuration information
*/
@@ -173,7 +198,6 @@ typedef struct _rrScrPriv {
int nSizes;
RRScreenSizePtr pSizes;
- RRScreenSizePtr pSize;
Rotation rotation;
int rate;
int size;
@@ -190,6 +214,7 @@ extern int rrPrivIndex;
void
RRExtensionInit (void);
+#ifdef RANDR_12_INTERFACE
/*
* Set the range of sizes for the screen
*/
@@ -199,89 +224,34 @@ RRScreenSetSizeRange (ScreenPtr pScreen,
CARD16 minHeight,
CARD16 maxWidth,
CARD16 maxHeight);
+#endif
+/* rrscreen.c */
/*
- * Create a CRTC
- */
-RRCrtcPtr
-RRCrtcCreate (ScreenPtr pScreen,
- void *devPrivate);
-
-
-/*
- * Use this value for any num parameter to indicate that
- * the related data are unchanged
- */
-#define RR_NUM_UNCHANGED -1
-
-/*
- * Notify the extension that the Crtc has been reconfigured
- */
-Bool
-RRCrtcSet (RRCrtcPtr crtc,
- RRModePtr mode,
- int x,
- int y,
- Rotation rotation,
- int numOutput,
- RROutputPtr *outputs);
-
-/*
- * Destroy a Crtc at shutdown
- */
-void
-RRCrtcDestroy (RRCrtcPtr crtc);
-
-/*
- * Find, and if necessary, create a mode
- */
-
-RRModePtr
-RRModeGet (ScreenPtr pScreen,
- xRRModeInfo *modeInfo,
- char *name);
-
-/*
- * Destroy a mode.
+ * Notify the extension that the screen size has been changed.
+ * The driver is responsible for calling this whenever it has changed
+ * the size of the screen
*/
-
void
-RRModeDestroy (RRModePtr mode);
+RRScreenSizeNotify (ScreenPtr pScreen);
/*
- * Create an output
+ * Request that the screen be resized
*/
-
-RROutputPtr
-RROutputCreate (ScreenPtr pScreen,
- char *name,
- int nameLength,
- void *devPrivate);
+Bool
+RRScreenSizeSet (ScreenPtr pScreen,
+ CARD16 width,
+ CARD16 height,
+ CARD32 mmWidth,
+ CARD32 mmHeight);
/*
- * Notify extension that output parameters have been changed
+ * Deliver a ScreenNotify event
*/
-Bool
-RROutputSet (RROutputPtr output,
- RROutputPtr *clones,
- int numClones,
- RRModePtr *modes,
- int numModes,
- RRCrtcPtr *crtcs,
- int numCrtcs,
- CARD8 connection);
-
void
-RROutputDestroy (RROutputPtr output);
-
-void
-RRTellChanged (ScreenPtr pScreen);
-
-Bool RRScreenInit(ScreenPtr pScreen);
-
-Rotation
-RRGetRotation (ScreenPtr pScreen);
-
+RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen);
+
+/* mirandr.c */
Bool
miRandRInit (ScreenPtr pScreen);
@@ -301,7 +271,22 @@ miRRCrtcSet (ScreenPtr pScreen,
int numOutput,
RROutputPtr *outputs);
-#ifdef RANDR_SCREEN_INTERFACE
+/* randr.c */
+/*
+ * Send all pending events
+ */
+void
+RRTellChanged (ScreenPtr pScreen);
+
+Bool RRScreenInit(ScreenPtr pScreen);
+
+Rotation
+RRGetRotation (ScreenPtr pScreen);
+
+CARD16
+RRVerticalRefresh (xRRModeInfo *mode);
+
+#ifdef RANDR_10_INTERFACE
/*
* This is the old interface, deprecated but left
* around for compatibility
@@ -344,4 +329,122 @@ RRSetScreenConfig (ScreenPtr pScreen,
RRScreenSizePtr pSize);
#endif
+
+/* rrcrtc.c */
+/*
+ * Create a CRTC
+ */
+RRCrtcPtr
+RRCrtcCreate (ScreenPtr pScreen,
+ void *devPrivate);
+
+
+/*
+ * Use this value for any num parameter to indicate that
+ * the related data are unchanged
+ */
+#define RR_NUM_UNCHANGED -1
+
+/*
+ * Notify the extension that the Crtc has been reconfigured,
+ * the driver calls this whenever it has updated the mode
+ */
+Bool
+RRCrtcNotify (RRCrtcPtr crtc,
+ RRModePtr mode,
+ int x,
+ int y,
+ Rotation rotation,
+ int numOutput,
+ RROutputPtr *outputs);
+
+/*
+ * Request that the Crtc be reconfigured
+ */
+Bool
+RRCrtcSet (RRCrtcPtr crtc,
+ RRModePtr mode,
+ int x,
+ int y,
+ Rotation rotation,
+ int numOutput,
+ RROutputPtr *outputs);
+
+/*
+ * Destroy a Crtc at shutdown
+ */
+void
+RRCrtcDestroy (RRCrtcPtr crtc);
+
+/*
+ * Initialize crtc type
+ */
+Bool
+RRCrtcInit (void);
+
+/* rrmode.c */
+/*
+ * Find, and if necessary, create a mode
+ */
+
+RRModePtr
+RRModeGet (ScreenPtr pScreen,
+ xRRModeInfo *modeInfo,
+ char *name);
+
+/*
+ * Destroy a mode.
+ */
+
+void
+RRModeDestroy (RRModePtr mode);
+
+/*
+ * Initialize mode type
+ */
+Bool
+RRModeInit (void);
+
+/* rroutput.c */
+/*
+ * Create an output
+ */
+
+RROutputPtr
+RROutputCreate (ScreenPtr pScreen,
+ char *name,
+ int nameLength,
+ void *devPrivate);
+
+/*
+ * Notify extension that output parameters have been changed
+ */
+Bool
+RROutputSetClones (RROutputPtr output,
+ RROutputPtr *clones,
+ int numClones);
+
+Bool
+RROutputSetModes (RROutputPtr output,
+ RRModePtr *modes,
+ int numModes);
+
+Bool
+RROutputSetCrtcs (RROutputPtr output,
+ RRCrtcPtr *crtcs,
+ int numCrtcs);
+
+Bool
+RROutputSetConnection (RROutputPtr output,
+ CARD8 connection);
+
+void
+RROutputDestroy (RROutputPtr output);
+
+/*
+ * Initialize output type
+ */
+Bool
+RROutputInit (void);
+
#endif /* _RANDRSTR_H_ */
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
new file mode 100644
index 000000000..cc5b24d50
--- /dev/null
+++ b/randr/rrcrtc.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+
+static RESTYPE CrtcType;
+
+/*
+ * Create a CRTC
+ */
+RRCrtcPtr
+RRCrtcCreate (ScreenPtr pScreen,
+ void *devPrivate)
+{
+ rrScrPriv (pScreen);
+ RRCrtcPtr crtc;
+ RRCrtcPtr *crtcs;
+
+ crtc = xalloc (sizeof (RRCrtcRec));
+ if (!crtc)
+ return NULL;
+ if (pScrPriv->numCrtcs)
+ crtcs = xrealloc (pScrPriv->crtcs,
+ (pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr));
+ else
+ crtcs = xalloc (sizeof (RRCrtcPtr));
+ if (!crtcs)
+ {
+ xfree (crtc);
+ return NULL;
+ }
+ crtc->id = FakeClientID (0);
+ crtc->pScreen = pScreen;
+ crtc->mode = NULL;
+ crtc->x = 0;
+ crtc->y = 0;
+ crtc->rotation = RR_Rotate_0;
+ crtc->rotations = RR_Rotate_0;
+ crtc->outputs = NULL;
+ crtc->numOutputs = 0;
+ crtc->changed = TRUE;
+ crtc->devPrivate = devPrivate;
+ pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc;
+ return crtc;
+}
+
+/*
+ * Notify the extension that the Crtc has been reconfigured,
+ * the driver calls this whenever it has updated the mode
+ */
+Bool
+RRCrtcNotify (RRCrtcPtr crtc,
+ RRModePtr mode,
+ int x,
+ int y,
+ Rotation rotation,
+ int numOutputs,
+ RROutputPtr *outputs)
+{
+ ScreenPtr pScreen = crtc->pScreen;
+ rrScrPriv(pScreen);
+ int i, j;
+ int prevNumOutputs = crtc->numOutputs;
+
+ if (numOutputs != prevNumOutputs)
+ {
+ RROutputPtr *outputs;
+
+ if (crtc->numOutputs)
+ outputs = xrealloc (crtc->outputs,
+ numOutputs * sizeof (RROutputPtr));
+ else
+ outputs = xalloc (numOutputs * sizeof (RROutputPtr));
+ if (!outputs)
+ return FALSE;
+ crtc->outputs = outputs;
+ }
+ for (i = 0; i < numOutputs; i++)
+ {
+ for (j = 0; j < crtc->numOutputs; j++)
+ if (outputs[i] == crtc->outputs[j])
+ break;
+ if (j != crtc->numOutputs)
+ {
+ outputs[i]->changed = TRUE;
+ crtc->changed = TRUE;
+ }
+ }
+ for (j = 0; j < crtc->numOutputs; j++)
+ {
+ for (i = 0; i < numOutputs; i++)
+ if (outputs[i] == crtc->outputs[j])
+ break;
+ if (i != numOutputs)
+ {
+ crtc->outputs[j]->changed = TRUE;
+ crtc->changed = TRUE;
+ }
+ }
+ if (mode != crtc->mode)
+ {
+ if (crtc->mode)
+ RRModeDestroy (crtc->mode);
+ crtc->mode = mode;
+ mode->refcnt++;
+ crtc->changed = TRUE;
+ }
+ if (x != crtc->x)
+ {
+ crtc->x = x;
+ crtc->changed = TRUE;
+ }
+ if (y != crtc->y)
+ {
+ crtc->y = y;
+ crtc->changed = TRUE;
+ }
+ if (rotation != crtc->rotation)
+ {
+ crtc->rotation = rotation;
+ crtc->changed = TRUE;
+ }
+ if (crtc->changed)
+ pScrPriv->changed = TRUE;
+ return TRUE;
+}
+
+/*
+ * Request that the Crtc be reconfigured
+ */
+Bool
+RRCrtcSet (RRCrtcPtr crtc,
+ RRModePtr mode,
+ int x,
+ int y,
+ Rotation rotation,
+ int numOutputs,
+ RROutputPtr *outputs)
+{
+ ScreenPtr pScreen = crtc->pScreen;
+ rrScrPriv(pScreen);
+
+#if RANDR_12_INTERFACE
+ if (pScrPriv->rrCrtcSet)
+ {
+ return (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y,
+ rotation, numOutputs, outputs);
+ }
+#endif
+#if RANDR_10_INTERFACE
+ if (pScrPriv->rrSetConfig)
+ {
+ RRScreenSize size;
+ RRScreenRate rate;
+ Bool ret;
+
+ size.width = mode->mode.width;
+ size.height = mode->mode.height;
+ size.mmWidth = mode->mode.mmWidth;
+ size.mmHeight = mode->mode.mmHeight;
+ size.nRates = 1;
+ rate.rate = RRVerticalRefresh (&mode->mode);
+ size.pRates = &rate;
+ ret = (*pScrPriv->rrSetConfig) (pScreen, rotation, rate.rate, &size);
+ /*
+ * Old 1.0 interface tied screen size to mode size
+ */
+ if (ret)
+ RRScreenSizeNotify (pScreen);
+ return ret;
+ }
+#endif
+ return FALSE;
+}
+
+/*
+ * Destroy a Crtc at shutdown
+ */
+void
+RRCrtcDestroy (RRCrtcPtr crtc)
+{
+ FreeResource (crtc->id, 0);
+}
+
+static int
+RRCrtcDestroyResource (pointer value, XID pid)
+{
+ RRCrtcPtr crtc = (RRCrtcPtr) value;
+ ScreenPtr pScreen = crtc->pScreen;
+ rrScrPriv(pScreen);
+ int i;
+
+ for (i = 0; i < pScrPriv->numCrtcs; i++)
+ {
+ if (pScrPriv->crtcs[i] == crtc)
+ {
+ memmove (pScrPriv->crtcs, pScrPriv->crtcs + 1,
+ (pScrPriv->numCrtcs - (i - 1)) * sizeof (RRCrtcPtr));
+ --pScrPriv->numCrtcs;
+ }
+ }
+ free (value);
+ return 1;
+}
+
+/*
+ * Initialize crtc type
+ */
+Bool
+RRCrtcInit (void)
+{
+ CrtcType = CreateNewResourceType (RRCrtcDestroyResource);
+ if (!CrtcType)
+ return FALSE;
+#ifdef XResExtension
+ RegisterResourceName (CrtcType, "CRTC");
+#endif
+ return TRUE;
+}
diff --git a/randr/rrmode.c b/randr/rrmode.c
new file mode 100644
index 000000000..1eb53c388
--- /dev/null
+++ b/randr/rrmode.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+
+static RESTYPE ModeType;
+
+RRModePtr
+RRModeGet (ScreenPtr pScreen,
+ xRRModeInfo *modeInfo,
+ char *name)
+{
+ rrScrPriv (pScreen);
+ int i;
+ RRModePtr mode;
+
+ for (i = 0; i < pScrPriv->numModes; i++)
+ {
+ mode = pScrPriv->modes[i];
+ if (!memcmp (modeInfo, &mode->mode, sizeof (xRRModeInfo)) &&
+ !memcmp (name, mode->name, modeInfo->nameLength))
+ {
+ ++mode->refcnt;
+ return mode;
+ }
+ }
+ mode = xalloc (sizeof (RRModeRec) + modeInfo->nameLength + 1);
+ mode->refcnt = 1;
+ mode->mode = *modeInfo;
+ mode->name = (char *) (mode + 1);
+ memcpy (mode->name, name, modeInfo->nameLength);
+ mode->name[modeInfo->nameLength] = '\0';
+ mode->id = FakeClientID(0);
+ if (!AddResource (mode->id, ModeType, (pointer) mode))
+ return NULL;
+ ++mode->refcnt;
+ pScrPriv->changed = TRUE;
+ return mode;
+}
+
+void
+RRModeDestroy (RRModePtr mode)
+{
+ if (--mode->refcnt > 0)
+ return;
+ xfree (mode);
+}
+
+static int
+RRModeDestroyResource (pointer value, XID pid)
+{
+ RRModeDestroy ((RRModePtr) value);
+ return 1;
+}
+
+Bool
+RRModeInit (void)
+{
+ ModeType = CreateNewResourceType (RRModeDestroyResource);
+ if (!ModeType)
+ return FALSE;
+#ifdef XResExtension
+ RegisterResourceName (ModeType, "MODE");
+#endif
+ return TRUE;
+}
diff --git a/randr/rroutput.c b/randr/rroutput.c
new file mode 100644
index 000000000..c7e7995fc
--- /dev/null
+++ b/randr/rroutput.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+
+static RESTYPE OutputType;
+
+/*
+ * Destroy a Output at shutdown
+ */
+void
+RROutputDestroy (RROutputPtr crtc)
+{
+ FreeResource (crtc->id, 0);
+}
+
+static int
+RROutputDestroyResource (pointer value, XID pid)
+{
+ free (value);
+ return 1;
+}
+
+/*
+ * Initialize crtc type
+ */
+Bool
+RROutputInit (void)
+{
+ OutputType = CreateNewResourceType (RROutputDestroyResource);
+ if (!OutputType)
+ return FALSE;
+#ifdef XResExtension
+ RegisterResourceName (OutputType, "OUTPUT");
+#endif
+ return TRUE;
+}
diff --git a/randr/rrscreen.c b/randr/rrscreen.c
new file mode 100644
index 000000000..47ba12d39
--- /dev/null
+++ b/randr/rrscreen.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright © 2006 Keith Packard
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include "randrstr.h"
+
+extern char *ConnectionInfo;
+
+static int padlength[4] = {0, 3, 2, 1};
+
+/*
+ * Edit connection information block so that new clients
+ * see the current screen size on connect
+ */
+static void
+RREditConnectionInfo (ScreenPtr pScreen)
+{
+ xConnSetup *connSetup;
+ char *vendor;
+ xPixmapFormat *formats;
+ xWindowRoot *root;
+ xDepth *depth;
+ xVisualType *visual;
+ int screen = 0;
+ int d;
+
+ connSetup = (xConnSetup *) ConnectionInfo;
+ vendor = (char *) connSetup + sizeof (xConnSetup);
+ formats = (xPixmapFormat *) ((char *) vendor +
+ connSetup->nbytesVendor +
+ padlength[connSetup->nbytesVendor & 3]);
+ root = (xWindowRoot *) ((char *) formats +
+ sizeof (xPixmapFormat) * screenInfo.numPixmapFormats);
+ while (screen != pScreen->myNum)
+ {
+ depth = (xDepth *) ((char *) root +
+ sizeof (xWindowRoot));
+ for (d = 0; d < root->nDepths; d++)
+ {
+ visual = (xVisualType *) ((char *) depth +
+ sizeof (xDepth));
+ depth = (xDepth *) ((char *) visual +
+ depth->nVisuals * sizeof (xVisualType));
+ }
+ root = (xWindowRoot *) ((char *) depth);
+ screen++;
+ }
+ root->pixWidth = pScreen->width;
+ root->pixHeight = pScreen->height;
+ root->mmWidth = pScreen->mmWidth;
+ root->mmHeight = pScreen->mmHeight;
+}
+
+static void
+RRSendConfigNotify (ScreenPtr pScreen)
+{
+ WindowPtr pWin = WindowTable[pScreen->myNum];
+ xEvent event;
+
+ event.u.u.type = ConfigureNotify;
+ event.u.configureNotify.window = pWin->drawable.id;
+ event.u.configureNotify.aboveSibling = None;
+ event.u.configureNotify.x = 0;
+ event.u.configureNotify.y = 0;
+
+ /* XXX xinerama stuff ? */
+
+ event.u.configureNotify.width = pWin->drawable.width;
+ event.u.configureNotify.height = pWin->drawable.height;
+ event.u.configureNotify.borderWidth = wBorderWidth (pWin);
+ event.u.configureNotify.override = pWin->overrideRedirect;
+ DeliverEvents(pWin, &event, 1, NullWindow);
+}
+
+void
+RRDeliverScreenEvent (ClientPtr client, WindowPtr pWin, ScreenPtr pScreen)
+{
+ rrScrPriv (pScreen);
+ xRRScreenChangeNotifyEvent se;
+ RRCrtcPtr crtc = pScrPriv->numCrtcs ? pScrPriv->crtcs[0] : NULL;
+ RROutputPtr output = pScrPriv->numOutputs ? pScrPriv->outputs[0] : NULL;
+ RRModePtr mode = crtc ? crtc->mode : NULL;
+ WindowPtr pRoot = WindowTable[pScreen->myNum];
+ int i;
+
+ se.type = RRScreenChangeNotify + RREventBase;
+ se.rotation = (CARD8) (crtc ? crtc->rotation : RR_Rotate_0);
+ se.timestamp = pScrPriv->lastSetTime.milliseconds;
+ se.sequenceNumber = client->sequence;
+ se.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
+ se.root = pRoot->drawable.id;
+ se.window = pWin->drawable.id;
+#ifdef RENDER
+ se.subpixelOrder = PictureGetSubpixelOrder (pScreen);
+#else
+ se.subpixelOrder = SubPixelUnknown;
+#endif
+
+ se.sequenceNumber = client->sequence;
+ if (mode)
+ {
+ se.sizeID = -1;
+ for (i = 0; i < output->numModes; i++)
+ if (mode == output->modes[i])
+ {
+ se.sizeID = i;
+ break;
+ }
+ se.widthInPixels = mode->mode.width;
+ se.heightInPixels = mode->mode.height;
+ se.widthInMillimeters = mode->mode.mmWidth;
+ se.heightInMillimeters = mode->mode.mmHeight;
+ }
+ else
+ {
+ /*
+ * This "shouldn't happen", but a broken DDX can
+ * forget to set the current configuration on GetInfo
+ */
+ se.sizeID = 0xffff;
+ se.widthInPixels = 0;
+ se.heightInPixels = 0;
+ se.widthInMillimeters = 0;
+ se.heightInMillimeters = 0;
+ }
+ WriteEventsToClient (client, 1, (xEvent *) &se);
+}
+
+/*
+ * Notify the extension that the screen size has been changed.
+ * The driver is responsible for calling this whenever it has changed
+ * the size of the screen
+ */
+void
+RRScreenSizeNotify (ScreenPtr pScreen)
+{
+ rrScrPriv(pScreen);
+ /*
+ * Deliver ConfigureNotify events when root changes
+ * pixel size
+ */
+ if (pScrPriv->width == pScreen->width &&
+ pScrPriv->height == pScreen->height)
+ return;
+
+ pScrPriv->width = pScreen->width;
+ pScrPriv->height = pScreen->height;
+ pScrPriv->changed = TRUE;
+
+ RRSendConfigNotify (pScreen);
+ RREditConnectionInfo (pScreen);
+
+ /*
+ * Fix pointer bounds and location
+ */
+ ScreenRestructured (pScreen);
+}
+
+/*
+ * Request that the screen be resized
+ */
+Bool
+RRScreenSizeSet (ScreenPtr pScreen,
+ CARD16 width,
+ CARD16 height,
+ CARD32 mmWidth,
+ CARD32 mmHeight)
+{
+ rrScrPriv(pScreen);
+
+#if RANDR_12_INTERFACE
+ if (pScrPriv->rrScreenSizeSet)
+ {
+ return (*pScrPriv->rrScreenSizeSet) (pScreen,
+ width, height,
+ mmWidth, mmHeight);
+ }
+#endif
+#if RANDR_10_INTERFACE
+ if (pScrPriv->rrSetConfig)
+ {
+ return TRUE; /* can't set size separately */
+ }
+#endif
+ return FALSE;
+}
+