xserver/hw/xfree86/common/xf86RandR.c

460 lines
12 KiB
C
Raw Normal View History

2003-11-14 16:48:57 +00:00
/*
*
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
2003-11-14 16:48:57 +00:00
*
* 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 Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD 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.
*/
#ifdef HAVE_XORG_CONFIG_H
#include <xorg-config.h>
#endif
#include <X11/X.h>
#include "os.h"
2003-11-14 16:48:57 +00:00
#include "mibank.h"
#include "globals.h"
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86DDC.h"
#include "mipointer.h"
#include <randrstr.h>
#include "inputstr.h"
2003-11-14 16:48:57 +00:00
typedef struct _xf86RandRInfo {
CreateScreenResourcesProcPtr CreateScreenResources;
CloseScreenProcPtr CloseScreen;
int virtualX;
int virtualY;
int mmWidth;
int mmHeight;
Rotation rotation;
2003-11-14 16:48:57 +00:00
} XF86RandRInfoRec, *XF86RandRInfoPtr;
static int xf86RandRKeyIndex;
static DevPrivateKey xf86RandRKey;
2003-11-14 16:48:57 +00:00
#define XF86RANDRINFO(p) ((XF86RandRInfoPtr)dixLookupPrivate(&(p)->devPrivates, xf86RandRKey))
2003-11-14 16:48:57 +00:00
static int
xf86RandRModeRefresh (DisplayModePtr mode)
{
if (mode->VRefresh)
return (int) (mode->VRefresh + 0.5);
else if (mode->Clock == 0)
return 0;
2003-11-14 16:48:57 +00:00
else
return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5);
2003-11-14 16:48:57 +00:00
}
static Bool
xf86RandRGetInfo (ScreenPtr pScreen, Rotation *rotations)
{
RRScreenSizePtr pSize;
ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
DisplayModePtr mode;
int refresh0 = 60;
xorgRRModeMM RRModeMM;
2003-11-14 16:48:57 +00:00
*rotations = RR_Rotate_0;
for (mode = scrp->modes; mode != NULL ; mode = mode->next)
2003-11-14 16:48:57 +00:00
{
int refresh = xf86RandRModeRefresh (mode);
2003-11-14 16:48:57 +00:00
if (mode == scrp->modes)
refresh0 = refresh;
RRModeMM.mode = mode;
RRModeMM.virtX = randrp->virtualX;
RRModeMM.virtY = randrp->virtualY;
RRModeMM.mmWidth = randrp->mmWidth;
RRModeMM.mmHeight = randrp->mmHeight;
if(scrp->DriverFunc) {
(*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM);
}
2003-11-14 16:48:57 +00:00
pSize = RRRegisterSize (pScreen,
mode->HDisplay, mode->VDisplay,
RRModeMM.mmWidth, RRModeMM.mmHeight);
2003-11-14 16:48:57 +00:00
if (!pSize)
return FALSE;
RRRegisterRate (pScreen, pSize, refresh);
if (mode == scrp->currentMode &&
mode->HDisplay == scrp->virtualX && mode->VDisplay == scrp->virtualY)
RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize);
2003-11-14 16:48:57 +00:00
if (mode->next == scrp->modes)
break;
}
if (scrp->currentMode->HDisplay != randrp->virtualX ||
scrp->currentMode->VDisplay != randrp->virtualY)
2003-11-14 16:48:57 +00:00
{
mode = scrp->modes;
RRModeMM.mode = NULL;
RRModeMM.virtX = randrp->virtualX;
RRModeMM.virtY = randrp->virtualY;
RRModeMM.mmWidth = randrp->mmWidth;
RRModeMM.mmHeight = randrp->mmHeight;
if(scrp->DriverFunc) {
(*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM);
}
2003-11-14 16:48:57 +00:00
pSize = RRRegisterSize (pScreen,
randrp->virtualX, randrp->virtualY,
RRModeMM.mmWidth, RRModeMM.mmHeight);
2003-11-14 16:48:57 +00:00
if (!pSize)
return FALSE;
RRRegisterRate (pScreen, pSize, refresh0);
if (scrp->virtualX == randrp->virtualX &&
scrp->virtualY == randrp->virtualY)
2003-11-14 16:48:57 +00:00
{
RRSetCurrentConfig (pScreen, randrp->rotation, refresh0, pSize);
2003-11-14 16:48:57 +00:00
}
}
/* If there is driver support for randr, let it set our supported rotations */
if(scrp->DriverFunc) {
xorgRRRotation RRRotation;
RRRotation.RRRotations = *rotations;
if (!(*scrp->DriverFunc)(scrp, RR_GET_INFO, &RRRotation))
return TRUE;
*rotations = RRRotation.RRRotations;
}
2003-11-14 16:48:57 +00:00
return TRUE;
}
static Bool
xf86RandRSetMode (ScreenPtr pScreen,
DisplayModePtr mode,
Bool useVirtual,
int mmWidth,
int mmHeight)
2003-11-14 16:48:57 +00:00
{
ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
int oldWidth = pScreen->width;
int oldHeight = pScreen->height;
int oldmmWidth = pScreen->mmWidth;
int oldmmHeight = pScreen->mmHeight;
int oldVirtualX = scrp->virtualX;
int oldVirtualY = scrp->virtualY;
2003-11-14 16:48:57 +00:00
WindowPtr pRoot = WindowTable[pScreen->myNum];
Bool ret = TRUE;
2003-11-14 16:48:57 +00:00
if (pRoot)
(*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE);
2003-11-14 16:48:57 +00:00
if (useVirtual)
{
scrp->virtualX = randrp->virtualX;
scrp->virtualY = randrp->virtualY;
}
else
{
scrp->virtualX = mode->HDisplay;
scrp->virtualY = mode->VDisplay;
}
/*
* The DIX forgets the physical dimensions we passed into RRRegisterSize, so
* reconstruct them if possible.
*/
if(scrp->DriverFunc) {
xorgRRModeMM RRModeMM;
RRModeMM.mode = mode;
RRModeMM.virtX = scrp->virtualX;
RRModeMM.virtY = scrp->virtualY;
RRModeMM.mmWidth = mmWidth;
RRModeMM.mmHeight = mmHeight;
(*scrp->DriverFunc)(scrp, RR_GET_MODE_MM, &RRModeMM);
mmWidth = RRModeMM.mmWidth;
mmHeight = RRModeMM.mmHeight;
}
if(randrp->rotation & (RR_Rotate_90 | RR_Rotate_270))
{
/* If the screen is rotated 90 or 270 degrees, swap the sizes. */
pScreen->width = scrp->virtualY;
pScreen->height = scrp->virtualX;
pScreen->mmWidth = mmHeight;
pScreen->mmHeight = mmWidth;
}
else
{
pScreen->width = scrp->virtualX;
pScreen->height = scrp->virtualY;
pScreen->mmWidth = mmWidth;
pScreen->mmHeight = mmHeight;
}
2003-11-14 16:48:57 +00:00
if (!xf86SwitchMode (pScreen, mode))
{
pScreen->width = oldWidth;
pScreen->height = oldHeight;
pScreen->mmWidth = oldmmWidth;
pScreen->mmHeight = oldmmHeight;
scrp->virtualX = oldVirtualX;
scrp->virtualY = oldVirtualY;
ret = FALSE;
2003-11-14 16:48:57 +00:00
}
/*
* Make sure the layout is correct
*/
xf86ReconfigureLayout();
/*
* Make sure the whole screen is visible
*/
xf86SetViewport (pScreen, pScreen->width, pScreen->height);
xf86SetViewport (pScreen, 0, 0);
if (pRoot)
(*scrp->EnableDisableFBAccess) (pScreen->myNum, TRUE);
return ret;
2003-11-14 16:48:57 +00:00
}
static Bool
xf86RandRSetConfig (ScreenPtr pScreen,
Rotation rotation,
int rate,
RRScreenSizePtr pSize)
{
ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
DisplayModePtr mode;
int px, py;
Bool useVirtual = FALSE;
Rotation oldRotation = randrp->rotation;
2003-11-14 16:48:57 +00:00
2008-07-04 04:03:46 -03:00
miPointerGetPosition(inputInfo.pointer, &px, &py);
2003-11-14 16:48:57 +00:00
for (mode = scrp->modes; ; mode = mode->next)
{
if (mode->HDisplay == pSize->width &&
2003-11-14 16:48:57 +00:00
mode->VDisplay == pSize->height &&
(rate == 0 || xf86RandRModeRefresh (mode) == rate))
break;
if (mode->next == scrp->modes)
{
if (pSize->width == randrp->virtualX &&
pSize->height == randrp->virtualY)
{
mode = scrp->modes;
useVirtual = TRUE;
break;
}
return FALSE;
}
}
if (randrp->rotation != rotation) {
/* Have the driver do its thing. */
if (scrp->DriverFunc) {
xorgRRRotation RRRotation;
RRRotation.RRConfig.rotation = rotation;
RRRotation.RRConfig.rate = rate;
RRRotation.RRConfig.width = pSize->width;
RRRotation.RRConfig.height = pSize->height;
/*
* Currently we need to rely on HW support for rotation.
*/
if (!(*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation))
return FALSE;
} else
return FALSE;
randrp->rotation = rotation;
}
if (!xf86RandRSetMode (pScreen, mode, useVirtual, pSize->mmWidth, pSize->mmHeight)) {
if(randrp->rotation != oldRotation) {
/* Have the driver undo its thing. */
if (scrp->DriverFunc) {
xorgRRRotation RRRotation;
RRRotation.RRConfig.rotation = oldRotation;
RRRotation.RRConfig.rate = xf86RandRModeRefresh (scrp->currentMode);
RRRotation.RRConfig.width = scrp->virtualX;
RRRotation.RRConfig.height = scrp->virtualY;
(*scrp->DriverFunc)(scrp, RR_SET_CONFIG, &RRRotation);
}
randrp->rotation = oldRotation;
}
2003-11-14 16:48:57 +00:00
return FALSE;
}
2003-11-14 16:48:57 +00:00
/*
* Move the cursor back where it belongs; SwitchMode repositions it
*/
if (pScreen == miPointerCurrentScreen ())
{
px = (px >= pScreen->width ? (pScreen->width - 1) : px);
py = (py >= pScreen->height ? (pScreen->height - 1) : py);
2005-10-10 09:31:49 +00:00
xf86SetViewport(pScreen, px, py);
(*pScreen->SetCursorPosition) (inputInfo.pointer, pScreen, px, py, FALSE);
2003-11-14 16:48:57 +00:00
}
2003-11-14 16:48:57 +00:00
return TRUE;
}
/*
* Wait until the screen is initialized before whacking the
* sizes around; otherwise the screen pixmap will be allocated
* at the current mode size rather than the maximum size
*/
static Bool
xf86RandRCreateScreenResources (ScreenPtr pScreen)
{
XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
#if 0
ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
2003-11-14 16:48:57 +00:00
DisplayModePtr mode;
#endif
2003-11-14 16:48:57 +00:00
pScreen->CreateScreenResources = randrp->CreateScreenResources;
if (!(*pScreen->CreateScreenResources) (pScreen))
return FALSE;
#if 0
2003-11-14 16:48:57 +00:00
mode = scrp->currentMode;
if (mode)
xf86RandRSetMode (pScreen, mode, TRUE);
#endif
2003-11-14 16:48:57 +00:00
return TRUE;
}
/*
* Reset size back to original
*/
static Bool
xf86RandRCloseScreen (int index, ScreenPtr pScreen)
{
ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
2003-11-14 16:48:57 +00:00
scrp->virtualX = pScreen->width = randrp->virtualX;
scrp->virtualY = pScreen->height = randrp->virtualY;
scrp->currentMode = scrp->modes;
pScreen->CloseScreen = randrp->CloseScreen;
xfree (randrp);
dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, NULL);
2003-11-14 16:48:57 +00:00
return (*pScreen->CloseScreen) (index, pScreen);
}
_X_EXPORT Rotation
xf86GetRotation(ScreenPtr pScreen)
{
if (xf86RandRKey == NULL)
return RR_Rotate_0;
2005-10-11 14:50:47 +00:00
return XF86RANDRINFO(pScreen)->rotation;
}
/* Function to change RandR's idea of the virtual screen size */
_X_EXPORT Bool
xf86RandRSetNewVirtualAndDimensions(ScreenPtr pScreen,
int newvirtX, int newvirtY, int newmmWidth, int newmmHeight,
Bool resetMode)
{
XF86RandRInfoPtr randrp;
if (xf86RandRKey == NULL)
return FALSE;
randrp = XF86RANDRINFO(pScreen);
if (randrp == NULL)
return FALSE;
if (newvirtX > 0)
randrp->virtualX = newvirtX;
if (newvirtY > 0)
randrp->virtualY = newvirtY;
if (newmmWidth > 0)
randrp->mmWidth = newmmWidth;
if (newmmHeight > 0)
randrp->mmHeight = newmmHeight;
/* This is only for during server start */
if (resetMode) {
return (xf86RandRSetMode(pScreen,
XF86SCRNINFO(pScreen)->currentMode,
TRUE,
pScreen->mmWidth, pScreen->mmHeight));
}
return TRUE;
}
Export symbols defined in the sdk. This is the biggest "visibility" patch. Instead of doing a "export" symbol on demand, export everything in the sdk, so that if some module fails due to an unresolved symbol, it is because it is using a symbol not in the sdk. Most exported symbols shouldn't really be made visible, neither advertised in the sdk, as they are only used by a single shared object. Symbols in the sdk (or referenced in sdk macros), but not defined anywhere include: XkbBuildCoreState() XkbInitialMap XkbXIUnsupported XkbCheckActionVMods() XkbSendCompatNotify() XkbDDXFakePointerButton() XkbDDXApplyConfig() _XkbStrCaseCmp() _XkbErrMessages[] _XkbErrCode _XkbErrLocation _XkbErrData XkbAccessXDetailText() XkbNKNDetailMaskText() XkbLookupGroupAndLevel() XkbInitAtoms() XkbGetOrderedDrawables() XkbFreeOrderedDrawables() XkbConvertXkbComponents() XkbWriteXKBSemantics() XkbWriteXKBLayout() XkbWriteXKBKeymap() XkbWriteXKBFile() XkbWriteCFile() XkbWriteXKMFile() XkbWriteToServer() XkbMergeFile() XkmFindTOCEntry() XkmReadFileSection() XkmReadFileSectionName() InitExtInput() xf86CheckButton() xf86SwitchCoreDevice() RamDacSetGamma() RamDacRestoreDACValues() xf86Bpp xf86ConfigPix24 xf86MouseCflags[] xf86SupportedMouseTypes[] xf86NumMouseTypes xf86ChangeBusIndex() xf86EntityEnter() xf86EntityLeave() xf86WrapperInit() xf86RingBell() xf86findOptionBoolean() xf86debugListOptions() LoadSubModuleLocal() LoaderSymbolLocal() getInt10Rec() xf86CurrentScreen xf86ReallocatePciResources() xf86NewSerialNumber() xf86RandRSetInitialMode() fbCompositeSolidMask_nx1xn fbCompositeSolidMask_nx8888x0565C fbCompositeSolidMask_nx8888x8888C fbCompositeSolidMask_nx8x0565 fbCompositeSolidMask_nx8x0888 fbCompositeSolidMask_nx8x8888 fbCompositeSrc_0565x0565 fbCompositeSrc_8888x0565 fbCompositeSrc_8888x0888 fbCompositeSrc_8888x8888 fbCompositeSrcAdd_1000x1000 fbCompositeSrcAdd_8000x8000 fbCompositeSrcAdd_8888x8888 fbGeneration fbIn fbOver fbOver24 fbOverlayGeneration fbRasterizeEdges fbRestoreAreas fbSaveAreas composeFunctions VBEBuildVbeModeList() VBECalcVbeModeIndex() TIramdac3030CalculateMNPForClock() shadowBufPtr shadowFindBuf() miRRGetScreenInfo() RRSetScreenConfig() RRModePruneUnused() PixmanImageFromPicture() extern int miPointerGetMotionEvents() miClipPicture() miRasterizeTriangle() fbPush1toN() fbInitializeBackingStore() ddxBeforeReset() SetupSprite() InitSprite() DGADeliverEvent() SPECIAL CASES o defined as _X_INTERNAL xf86NewInputDevice() o defined as static fbGCPrivateKey fbOverlayScreenPrivateKey fbScreenPrivateKey fbWinPrivateKey o defined in libXfont.so, but declared in xorg/dixfont.h GetGlyphs() QueryGlyphExtents() QueryTextExtents() ParseGlyphCachingMode() InitGlyphCaching() SetGlyphCachingMode()
2008-11-29 23:56:06 -02:00
_X_EXPORT Bool
2003-11-14 16:48:57 +00:00
xf86RandRInit (ScreenPtr pScreen)
{
rrScrPrivPtr rp;
XF86RandRInfoPtr randrp;
ScrnInfoPtr scrp = XF86SCRNINFO(pScreen);
2003-11-14 16:48:57 +00:00
#ifdef PANORAMIX
/* XXX disable RandR when using Xinerama */
if (!noPanoramiXExtension)
return TRUE;
#endif
xf86RandRKey = &xf86RandRKeyIndex;
2003-11-14 16:48:57 +00:00
randrp = xalloc (sizeof (XF86RandRInfoRec));
if (!randrp)
return FALSE;
2003-11-14 16:48:57 +00:00
if (!RRScreenInit (pScreen))
{
xfree (randrp);
return FALSE;
}
rp = rrGetScrPriv(pScreen);
rp->rrGetInfo = xf86RandRGetInfo;
rp->rrSetConfig = xf86RandRSetConfig;
randrp->virtualX = scrp->virtualX;
randrp->virtualY = scrp->virtualY;
randrp->mmWidth = pScreen->mmWidth;
randrp->mmHeight = pScreen->mmHeight;
2003-11-14 16:48:57 +00:00
randrp->CreateScreenResources = pScreen->CreateScreenResources;
pScreen->CreateScreenResources = xf86RandRCreateScreenResources;
2003-11-14 16:48:57 +00:00
randrp->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = xf86RandRCloseScreen;
randrp->rotation = RR_Rotate_0;
dixSetPrivate(&pScreen->devPrivates, xf86RandRKey, randrp);
2003-11-14 16:48:57 +00:00
return TRUE;
}