diff options
Diffstat (limited to 'hw/xfree86')
86 files changed, 8380 insertions, 816 deletions
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am index f0c9e56f3..ec6a7acb5 100644 --- a/hw/xfree86/Makefile.am +++ b/hw/xfree86/Makefile.am @@ -8,16 +8,24 @@ if XF86UTILS XF86UTILS_SUBDIR = utils endif +if MFB +MFB_SUBDIR = xf1bpp xf4bpp +endif + +if CFB +CFB_SUBDIR = xf8_16bpp xf8_32bpp +endif + DOC_SUBDIR = doc SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support parser rac \ - ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp xf8_16bpp \ - xf8_32bpp loader dixmods exa \ + ramdac shadowfb vbe vgahw xaa $(MFB_SUBDIR) $(CFB_SUBDIR) \ + loader dixmods exa modes \ $(DRI_SUBDIR) $(XF86UTILS_SUBDIR) $(DOC_SUBDIR) DIST_SUBDIRS = common ddc dummylib i2c x86emu int10 fbdevhw os-support \ parser rac ramdac shadowfb vbe vgahw xaa xf1bpp xf4bpp \ - xf8_16bpp xf8_32bpp loader dixmods dri exa \ + xf8_16bpp xf8_32bpp loader dixmods dri exa modes \ utils doc bin_PROGRAMS = Xorg @@ -47,6 +55,10 @@ XORG_LIBS = \ rac/librac.a \ parser/libxf86config.a \ dixmods/libdixmods.la \ + modes/libxf86modes.a \ + ramdac/libramdac.a \ + ddc/libddc.a \ + i2c/libi2c.a \ @XORG_LIBS@ Xorg_DEPENDENCIES = \ diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c index 86ad0182d..686e1eeac 100644 --- a/hw/xfree86/common/xf86Bus.c +++ b/hw/xfree86/common/xf86Bus.c @@ -1796,6 +1796,15 @@ convertRange2Host(int entityIndex, resRange *pRange) } } +static void +xf86ConvertListToHost(int entityIndex, resPtr list) +{ + while (list) { + convertRange2Host(entityIndex, &list->val); + list = list->next; + } +} + /* * xf86RegisterResources() -- attempts to register listed resources. * If list is NULL it tries to obtain resources implicitly. Function @@ -2835,18 +2844,7 @@ xf86IsSubsetOf(resRange range, resPtr list) return ret; } -Bool -xf86IsListSubsetOf(resPtr list, resPtr BaseList) -{ - while (list) { - if (! xf86IsSubsetOf(list->val,BaseList)) - return FALSE; - list = list->next; - } - return TRUE; -} - -resPtr +static resPtr findIntersect(resRange Range, resPtr list) { resRange range; @@ -3070,15 +3068,6 @@ xf86NoSharedResources(int screenIndex,resType res) return TRUE; } -void -xf86ConvertListToHost(int entityIndex, resPtr list) -{ - while (list) { - convertRange2Host(entityIndex, &list->val); - list = list->next; - } -} - _X_EXPORT void xf86RegisterStateChangeNotificationCallback(xf86StateChangeNotificationCallbackFunc func, pointer arg) { diff --git a/hw/xfree86/common/xf86Bus.h b/hw/xfree86/common/xf86Bus.h index f1fc627b9..5ea5cc8e1 100644 --- a/hw/xfree86/common/xf86Bus.h +++ b/hw/xfree86/common/xf86Bus.h @@ -140,12 +140,9 @@ int xf86AllocateEntity(void); BusType StringToBusType(const char* busID, const char **retID); memType ChkConflict(resRange *rgp, resPtr res, xf86State state); Bool xf86IsSubsetOf(resRange range, resPtr list); -Bool xf86IsListSubsetOf(resPtr list, resPtr BaseList); resPtr xf86ExtractTypeFromList(resPtr list, unsigned long type); -resPtr findIntersect(resRange Range, resPtr list); resPtr xf86FindIntersect(resRange Range, resPtr list); void RemoveOverlaps(resPtr target, resPtr list, Bool pow2Alignment, Bool useEstimated); -void xf86ConvertListToHost(int entityIndex, resPtr list); #endif /* _XF86_BUS_H */ diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index 676392c04..986244557 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -76,7 +76,7 @@ extern DeviceAssocRec mouse_assoc; #ifdef XKB #undef XKB_IN_SERVER #define XKB_IN_SERVER -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> #endif #ifdef RENDER @@ -539,25 +539,6 @@ xf86DriverlistFromCompile(void) return driverlist; } - -char ** -xf86InputDriverlistFromCompile(void) -{ - static char **driverlist = NULL; - static Bool generated = FALSE; - - /* This string is modified in-place */ - static char drivernames[] = IDRIVERS; - - if (!generated) { - generated = TRUE; - driverlist = GenerateDriverlist("input", drivernames); - } - - return driverlist; -} - - /* * xf86ConfigError -- * Print a READABLE ErrorMessage!!! All information that is @@ -2506,17 +2487,8 @@ xf86HandleConfigFile(Bool autoconfig) return CONFIG_OK; } - -/* These make the equivalent parser functions visible to the common layer. */ -Bool -xf86PathIsAbsolute(const char *path) -{ - return (xf86pathIsAbsolute(path) != 0); -} - Bool xf86PathIsSafe(const char *path) { return (xf86pathIsSafe(path) != 0); } - diff --git a/hw/xfree86/common/xf86Config.h b/hw/xfree86/common/xf86Config.h index 0786ec6fe..3787ba21e 100644 --- a/hw/xfree86/common/xf86Config.h +++ b/hw/xfree86/common/xf86Config.h @@ -53,7 +53,6 @@ char ** xf86ModulelistFromConfig(pointer **); char ** xf86DriverlistFromConfig(void); char ** xf86DriverlistFromCompile(void); char ** xf86InputDriverlistFromConfig(void); -char ** xf86InputDriverlistFromCompile(void); Bool xf86BuiltinInputDriver(const char *); ConfigStatus xf86HandleConfigFile(Bool); diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 741e46b5b..0b7297511 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -69,7 +69,7 @@ static int nDevToConfig = 0, CurrentDriver; _X_EXPORT xf86MonPtr ConfiguredMonitor; Bool xf86DoConfigurePass1 = TRUE; -Bool foundMouse = FALSE; +static Bool foundMouse = FALSE; #if defined(__UNIXOS2__) #define DFLT_MOUSE_DEV "mouse$" diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c index 204457fb1..43db1ee1a 100644 --- a/hw/xfree86/common/xf86DGA.c +++ b/hw/xfree86/common/xf86DGA.c @@ -43,7 +43,7 @@ #include "servermd.h" #include "micmap.h" #ifdef XKB -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> #endif #include "xf86Xinput.h" @@ -51,11 +51,14 @@ static unsigned long DGAGeneration = 0; static int DGAScreenIndex = -1; +static int mieq_installed = 0; static Bool DGACloseScreen(int i, ScreenPtr pScreen); static void DGADestroyColormap(ColormapPtr pmap); static void DGAInstallColormap(ColormapPtr pmap); static void DGAUninstallColormap(ColormapPtr pmap); +static void DGAHandleEvent(int screen_num, xEvent *event, + DeviceIntPtr device, int nevents); static void DGACopyModeInfo( @@ -96,7 +99,6 @@ typedef struct { Bool grabKeyboard; } DGAScreenRec, *DGAScreenPtr; - _X_EXPORT Bool DGAInit( ScreenPtr pScreen, @@ -146,7 +148,6 @@ DGAInit( modes[i].flags &= ~DGA_PIXMAP_AVAILABLE; #endif - pScreen->devPrivates[DGAScreenIndex].ptr = (pointer)pScreenPriv; pScreenPriv->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = DGACloseScreen; @@ -157,11 +158,6 @@ DGAInit( pScreenPriv->UninstallColormap = pScreen->UninstallColormap; pScreen->UninstallColormap = DGAUninstallColormap; - /* - * This is now set in InitOutput(). - * - pScrn->SetDGAMode = xf86SetDGAMode; - */ return TRUE; } @@ -247,12 +243,22 @@ FreeMarkedVisuals(ScreenPtr pScreen) } } - static Bool DGACloseScreen(int i, ScreenPtr pScreen) { DGAScreenPtr pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + if (XDGAEventBase) { + OsBlockSignals(); + ProcessInputEvents(); + mieqSetHandler(*XDGAEventBase + MotionNotify, NULL); + mieqSetHandler(*XDGAEventBase + ButtonPress, NULL); + mieqSetHandler(*XDGAEventBase + ButtonRelease, NULL); + mieqSetHandler(*XDGAEventBase + KeyPress, NULL); + mieqSetHandler(*XDGAEventBase + KeyRelease, NULL); + OsReleaseSignals(); + } + FreeMarkedVisuals(pScreen); pScreen->CloseScreen = pScreenPriv->CloseScreen; @@ -462,6 +468,15 @@ DGASetInputMode(int index, Bool keyboard, Bool mouse) { pScreenPriv->grabMouse = mouse; pScreenPriv->grabKeyboard = keyboard; + + if (!mieq_installed) { + mieqSetHandler(*XDGAEventBase + MotionNotify, DGAHandleEvent); + mieqSetHandler(*XDGAEventBase + ButtonPress, DGAHandleEvent); + mieqSetHandler(*XDGAEventBase + ButtonRelease, DGAHandleEvent); + mieqSetHandler(*XDGAEventBase + KeyPress, DGAHandleEvent); + mieqSetHandler(*XDGAEventBase + KeyRelease, DGAHandleEvent); + mieq_installed = 1; + } } } @@ -903,21 +918,93 @@ DGAVTSwitch(void) return TRUE; } +Bool +DGAStealKeyEvent(int index, int key_code, int is_down) +{ + DGAScreenPtr pScreenPriv; + dgaEvent de; + + if(DGAScreenIndex < 0) /* no DGA */ + return FALSE; + + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); -/* We have the power to steal or modify events that are about to get queued */ + if(!pScreenPriv || !pScreenPriv->grabKeyboard) /* no direct mode */ + return FALSE; + + de.u.u.type = *XDGAEventBase + (is_down ? KeyPress : KeyRelease); + de.u.u.detail = key_code; + de.u.event.time = GetTimeInMillis(); + mieqEnqueue (inputInfo.keyboard, (xEvent *) &de); + + return TRUE; +} + +static int DGAMouseX, DGAMouseY; Bool -DGAStealKeyEvent(int index, xEvent *e) +DGAStealMotionEvent(int index, int dx, int dy) { -} + DGAScreenPtr pScreenPriv; + dgaEvent de; -static int DGAMouseX, DGAMouseY; + if(DGAScreenIndex < 0) /* no DGA */ + return FALSE; + + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + if(!pScreenPriv || !pScreenPriv->grabMouse) /* no direct mode */ + return FALSE; + + DGAMouseX += dx; + if (DGAMouseX < 0) + DGAMouseX = 0; + else if (DGAMouseX > screenInfo.screens[index]->width) + DGAMouseX = screenInfo.screens[index]->width; + DGAMouseY += dy; + if (DGAMouseY < 0) + DGAMouseY = 0; + else if (DGAMouseY > screenInfo.screens[index]->height) + DGAMouseY = screenInfo.screens[index]->height; + de.u.u.type = *XDGAEventBase + MotionNotify; + de.u.u.detail = 0; + de.u.event.time = GetTimeInMillis(); + de.u.event.dx = dx; + de.u.event.dy = dy; + de.u.event.pad1 = DGAMouseX; + de.u.event.pad2 = DGAMouseY; + mieqEnqueue (inputInfo.pointer, (xEvent *) &de); + return TRUE; +} Bool -DGAStealMouseEvent(int index, xEvent *e, int dx, int dy) +DGAStealButtonEvent(int index, int button, int is_down) { + DGAScreenPtr pScreenPriv; + dgaEvent de; + + if (DGAScreenIndex < 0) + return FALSE; + + pScreenPriv = DGA_GET_SCREEN_PRIV(screenInfo.screens[index]); + + if (!pScreenPriv || !pScreenPriv->grabMouse) + return FALSE; + + de.u.u.type = *XDGAEventBase + (is_down ? ButtonPress : ButtonRelease); + de.u.u.detail = button; + de.u.event.time = GetTimeInMillis(); + de.u.event.dx = 0; + de.u.event.dy = 0; + de.u.event.pad1 = DGAMouseX; + de.u.event.pad2 = DGAMouseY; + mieqEnqueue (inputInfo.pointer, (xEvent *) &de); + + return TRUE; } +/* We have the power to steal or modify events that are about to get queued */ + Bool DGAIsDgaEvent (xEvent *e) { @@ -1124,39 +1211,6 @@ DGAProcessPointerEvent (ScreenPtr pScreen, dgaEvent *de, DeviceIntPtr mouse) } } -Bool -DGADeliverEvent (ScreenPtr pScreen, xEvent *e) -{ - dgaEvent *de = (dgaEvent *) e; - DGAScreenPtr pScreenPriv; - int coreEquiv; - - /* no DGA */ - if (DGAScreenIndex < 0 || XDGAEventBase == 0) - return FALSE; - pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); - - /* DGA not initialized on this screen */ - if (!pScreenPriv) - return FALSE; - - coreEquiv = de->u.u.type - *XDGAEventBase; - /* Not a DGA event */ - if (coreEquiv < KeyPress || coreEquiv > MotionNotify) - return FALSE; - - switch (coreEquiv) { - case KeyPress: - case KeyRelease: - DGAProcessKeyboardEvent (pScreen, de, inputInfo.keyboard); - break; - default: - DGAProcessPointerEvent (pScreen, de, inputInfo.pointer); - break; - } - return TRUE; -} - _X_EXPORT Bool DGAOpenFramebuffer( int index, @@ -1215,3 +1269,35 @@ DGAGetOldDGAMode(int index) return 0; } +static void +DGAHandleEvent(int screen_num, xEvent *event, DeviceIntPtr device, int nevents) +{ + dgaEvent *de = (dgaEvent *) event; + ScreenPtr pScreen = screenInfo.screens[screen_num]; + DGAScreenPtr pScreenPriv; + int coreEquiv; + + /* no DGA */ + if (DGAScreenIndex < 0 || XDGAEventBase == 0) + return; + pScreenPriv = DGA_GET_SCREEN_PRIV(pScreen); + + /* DGA not initialized on this screen */ + if (!pScreenPriv) + return; + + coreEquiv = de->u.u.type - *XDGAEventBase; + /* Not a DGA event; shouldn't happen, but you never know. */ + if (coreEquiv < KeyPress || coreEquiv > MotionNotify) + return; + + switch (coreEquiv) { + case KeyPress: + case KeyRelease: + DGAProcessKeyboardEvent (pScreen, de, inputInfo.keyboard); + break; + default: + DGAProcessPointerEvent (pScreen, de, inputInfo.pointer); + break; + } +} diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c index 05e62f184..3610c17c0 100644 --- a/hw/xfree86/common/xf86Events.c +++ b/hw/xfree86/common/xf86Events.c @@ -126,9 +126,9 @@ extern Bool noXkbExtension; */ #ifdef USE_VT_SYSREQ -Bool VTSysreqToggle = FALSE; +static Bool VTSysreqToggle = FALSE; #endif /* !USE_VT_SYSREQ */ -Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for +_X_EXPORT Bool VTSwitchEnabled = TRUE; /* Allows run-time disabling for *BSD and for avoiding VT switches when using the DRI automatic full screen mode.*/ diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c index d81b5cc91..7dc45b75d 100644 --- a/hw/xfree86/common/xf86Globals.c +++ b/hw/xfree86/common/xf86Globals.c @@ -146,7 +146,6 @@ _X_EXPORT confDRIRec xf86ConfigDRI = {0, }; XF86ConfigPtr xf86configptr = NULL; Bool xf86Resetting = FALSE; Bool xf86Initialising = FALSE; -Bool xf86ProbeFailed = FALSE; Bool xf86DoProbe = FALSE; Bool xf86DoConfigure = FALSE; DriverPtr *xf86DriverList = NULL; diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index 27a90c9a7..5353a5758 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -2986,3 +2986,16 @@ xf86IsUnblank(int mode) return TRUE; } } + +_X_EXPORT void +xf86MotionHistoryAllocate(LocalDevicePtr local) +{ + AllocateMotionHistory(local->dev); +} + +_X_EXPORT int +xf86GetMotionEvents(DeviceIntPtr pDev, xTimecoord *buff, unsigned long start, + unsigned long stop, ScreenPtr pScreen) +{ + return GetMotionHistory(pDev, buff, start, stop, pScreen); +} diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index f824f6867..17cc06bb4 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -36,6 +36,7 @@ #endif #include <stdlib.h> +#include <errno.h> #undef HAS_UTSNAME #if !defined(WIN32) && !defined(__UNIXOS2__) diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c index d5085b542..fc905dfac 100644 --- a/hw/xfree86/common/xf86Mode.c +++ b/hw/xfree86/common/xf86Mode.c @@ -368,6 +368,7 @@ xf86HandleBuiltinMode(ScrnInfoPtr scrp, return MODE_OK; } +#if 0 /** Calculates the horizontal sync rate of a mode */ _X_EXPORT double xf86ModeHSync(DisplayModePtr mode) @@ -411,6 +412,7 @@ xf86SetModeDefaultName(DisplayModePtr mode) mode->name = XNFprintf("%dx%d", mode->HDisplay, mode->VDisplay); } +#endif /* * xf86LookupMode @@ -680,6 +682,7 @@ xf86LookupMode(ScrnInfoPtr scrp, DisplayModePtr modep, } +#if 0 /* * xf86SetModeCrtc * @@ -733,7 +736,9 @@ xf86SetModeCrtc(DisplayModePtr p, int adjustFlags) p->CrtcHAdjusted = FALSE; p->CrtcVAdjusted = FALSE; } +#endif +#if 0 /** * Allocates and returns a copy of pMode, including pointers within pMode. */ @@ -814,6 +819,7 @@ xf86ModesEqual(DisplayModePtr pMode1, DisplayModePtr pMode2) return FALSE; } } +#endif /* * xf86CheckModeForMonitor @@ -2040,6 +2046,7 @@ add(char **p, char *new) strcat(*p, new); } +#if 0 _X_EXPORT void xf86PrintModeline(int scrnIndex,DisplayModePtr mode) { @@ -2075,6 +2082,7 @@ xf86PrintModeline(int scrnIndex,DisplayModePtr mode) mode->VTotal, flags); xfree(flags); } +#endif _X_EXPORT void xf86PrintModes(ScrnInfoPtr scrp) @@ -2145,6 +2153,7 @@ xf86PrintModes(ScrnInfoPtr scrp) } while (p != NULL && p != scrp->modes); } +#if 0 /** * Adds the new mode into the mode list, and returns the new list * @@ -2168,3 +2177,4 @@ xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new) return modes; } +#endif diff --git a/hw/xfree86/common/xf86Priv.h b/hw/xfree86/common/xf86Priv.h index 60fd31ab8..274f7e754 100644 --- a/hw/xfree86/common/xf86Priv.h +++ b/hw/xfree86/common/xf86Priv.h @@ -102,7 +102,6 @@ extern int xf86NumModuleInfos; extern int xf86NumDrivers; extern Bool xf86Resetting; extern Bool xf86Initialising; -extern Bool xf86ProbeFailed; extern int xf86NumScreens; extern xf86CurrentAccessRec xf86CurrentAccess; extern const char *xf86VisualNames[]; @@ -153,7 +152,6 @@ extern void xf86PostScreenInit(void); /* xf86Config.c */ -Bool xf86PathIsAbsolute(const char *path); Bool xf86PathIsSafe(const char *path); /* xf86DefaultModes */ diff --git a/hw/xfree86/common/xf86XKB.c b/hw/xfree86/common/xf86XKB.c index 399eb02d9..b805885bd 100644 --- a/hw/xfree86/common/xf86XKB.c +++ b/hw/xfree86/common/xf86XKB.c @@ -73,7 +73,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #define XF86_OS_PRIVS #include "xf86_OSlib.h" -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> void xf86InitXkb(void) diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index 16e330d43..17ffed899 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -90,6 +90,10 @@ #include "mi.h" +#ifdef XFreeXDGA +#include "dgaproc.h" +#endif + xEvent *xf86Events = NULL; static Bool @@ -128,6 +132,9 @@ xf86ProcessCommonOptions(LocalDevicePtr local, } else { xf86Msg(X_CONFIG, "%s: doesn't report drag events\n", local->name); } + + /* Backwards compatibility. */ + local->history_size = GetMotionHistorySize(); } /*********************************************************************** @@ -395,10 +402,12 @@ xf86PostMotionEvent(DeviceIntPtr device, { va_list var; int i = 0, nevents = 0; + int dx, dy; Bool drag = xf86SendDragEvents(device); int *valuators = NULL; int flags = 0; xEvent *xE = NULL; + int index; if (is_absolute) flags = POINTER_ABSOLUTE; @@ -412,6 +421,24 @@ xf86PostMotionEvent(DeviceIntPtr device, valuators[i] = va_arg(var, int); va_end(var); +#if XFreeXDGA + if (first_valuator == 0 && num_valuators >= 2) { + if (miPointerGetScreen(inputInfo.pointer)) { + index = miPointerGetScreen(inputInfo.pointer)->myNum; + if (is_absolute) { + dx = valuators[0] - device->valuator->lastx; + dy = valuators[1] - device->valuator->lasty; + } + else { + dx = valuators[0]; + dy = valuators[1]; + } + if (DGAStealMotionEvent(index, dx, dy)) + goto out; + } + } +#endif + if (!xf86Events) xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum()); if (!xf86Events) @@ -430,6 +457,7 @@ xf86PostMotionEvent(DeviceIntPtr device, } } +out: xfree(valuators); } @@ -476,6 +504,15 @@ xf86PostButtonEvent(DeviceIntPtr device, va_list var; int *valuators = NULL; int i = 0, nevents = 0; + int index; + +#if XFreeXDGA + if (miPointerGetScreen(inputInfo.pointer)) { + index = miPointerGetScreen(inputInfo.pointer)->myNum; + if (DGAStealButtonEvent(index, button, is_down)) + return; + } +#endif valuators = xcalloc(sizeof(int), num_valuators); @@ -552,6 +589,15 @@ xf86PostKeyboardEvent(DeviceIntPtr device, int is_down) { int nevents = 0, i = 0; + int index; + +#if XFreeXDGA + if (miPointerGetScreen(inputInfo.pointer)) { + index = miPointerGetScreen(inputInfo.pointer)->myNum; + if (DGAStealKeyEvent(index, key_code, is_down)) + return; + } +#endif if (!xf86Events) xf86Events = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum()); diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h index fe65643ce..b2bc8dec1 100644 --- a/hw/xfree86/common/xf86Xinput.h +++ b/hw/xfree86/common/xf86Xinput.h @@ -86,6 +86,9 @@ #define XI_PRIVATE(dev) \ (((LocalDevicePtr)((dev)->public.devicePrivate))->private) +/* Stupid API backwards-compatibility. */ +#define TS_Raw 60 +#define TS_Scaled 61 #ifdef XINPUT /* This holds the input driver entry and module information. */ @@ -144,6 +147,7 @@ typedef struct _LocalDeviceRec { InputDriverPtr drv; pointer module; pointer options; + unsigned int history_size; } LocalDeviceRec, *LocalDevicePtr, InputInfoRec, *InputInfoPtr; typedef struct _DeviceAssocRec @@ -191,6 +195,10 @@ InputInfoPtr xf86AllocateInput(InputDriverPtr drv, int flags); InputDriverPtr xf86LookupInputDriver(const char *name); InputInfoPtr xf86LookupInput(const char *name); void xf86DeleteInput(InputInfoPtr pInp, int flags); +void xf86MotionHistoryAllocate(LocalDevicePtr local); +int xf86GetMotionEvents(DeviceIntPtr dev, xTimecoord *buff, + unsigned long start, unsigned long stop, + ScreenPtr pScreen); /* xf86Option.c */ void xf86CollectInputOptions(InputInfoPtr pInfo, const char **defaultOpts, diff --git a/hw/xfree86/common/xf86fbman.c b/hw/xfree86/common/xf86fbman.c index d64cfaee4..537d53d7d 100644 --- a/hw/xfree86/common/xf86fbman.c +++ b/hw/xfree86/common/xf86fbman.c @@ -968,7 +968,7 @@ localAllocateOffscreenLinear( linear->size = h * w; linear->offset = (pitch * area->box.y1) + area->box.x1; if (gran > 1) - linear->offset += ((linear->offset + gran - 1) / gran) * gran; + linear->offset = ((linear->offset + gran - 1) / gran) * gran; linear->granularity = gran; linear->MoveLinearCallback = moveCB; linear->RemoveLinearCallback = removeCB; diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c index 3e908b86a..2b097d2db 100644 --- a/hw/xfree86/common/xf86xv.c +++ b/hw/xfree86/common/xf86xv.c @@ -110,7 +110,7 @@ static void xf86XVAdjustFrame(int index, int x, int y, int flags); static Bool xf86XVInitAdaptors(ScreenPtr, XF86VideoAdaptorPtr*, int); -int XF86XVWindowIndex = -1; +static int XF86XVWindowIndex = -1; int XF86XvScreenIndex = -1; static unsigned long XF86XVGeneration = 0; static unsigned long PortResource = 0; diff --git a/hw/xfree86/ddc/Makefile.am b/hw/xfree86/ddc/Makefile.am index a04b5e8fe..04d3e445c 100644 --- a/hw/xfree86/ddc/Makefile.am +++ b/hw/xfree86/ddc/Makefile.am @@ -1,11 +1,9 @@ sdk_HEADERS = edid.h vdif.h xf86DDC.h -module_LTLIBRARIES = libddc.la +noinst_LIBRARIES = libddc.a -libddc_la_LDFLAGS = -avoid-version -libddc_la_SOURCES = xf86DDC.c edid.c interpret_edid.c print_edid.c \ - interpret_vdif.c print_vdif.c ddcProperty.c \ - edid_modes.c +libddc_a_SOURCES = xf86DDC.c edid.c interpret_edid.c print_edid.c \ + interpret_vdif.c print_vdif.c ddcProperty.c INCLUDES = $(XORG_INCS) -I$(srcdir)/../i2c diff --git a/hw/xfree86/ddc/ddcProperty.c b/hw/xfree86/ddc/ddcProperty.c index 13083dd50..37efb5bd9 100644 --- a/hw/xfree86/ddc/ddcProperty.c +++ b/hw/xfree86/ddc/ddcProperty.c @@ -31,6 +31,7 @@ #include "property.h" #include "propertyst.h" #include "xf86DDC.h" +#include "xf86_ansic.h" #define EDID1_ATOM_NAME "XFree86_DDC_EDID1_RAWDATA" #define EDID2_ATOM_NAME "XFree86_DDC_EDID2_RAWDATA" diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c index dd64bd56f..21984bc04 100644 --- a/hw/xfree86/ddc/xf86DDC.c +++ b/hw/xfree86/ddc/xf86DDC.c @@ -15,48 +15,6 @@ static const OptionInfoRec *DDCAvailableOptions(void *unused); -static MODULESETUPPROTO(ddcSetup); - -static XF86ModuleVersionInfo ddcVersRec = -{ - "ddc", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 1, 0, 0, - ABI_CLASS_VIDEODRV, /* needs the video driver ABI */ - ABI_VIDEODRV_VERSION, - MOD_CLASS_NONE, - {0,0,0,0} -}; - -_X_EXPORT XF86ModuleData ddcModuleData = { &ddcVersRec, ddcSetup, NULL }; - -ModuleInfoRec DDC = { - 1, - "DDC", - NULL, - 0, - DDCAvailableOptions, -}; - -static pointer -ddcSetup(pointer module, pointer opts, int *errmaj, int *errmin) -{ - static Bool setupDone = FALSE; - - if (!setupDone) { - setupDone = TRUE; - xf86AddModuleInfo(&DDC, module); - } - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ - return (pointer)1; -} - #define RETRIES 4 static unsigned char *EDIDRead_DDC1( @@ -333,6 +291,12 @@ DDCRead_DDC2(int scrnIndex, I2CBusPtr pBus, int start, int len) unsigned char *R_Buffer; int i; + /* + * Slow down the bus so that older monitors don't + * miss things. + */ + pBus->RiseFallTime = 20; + if (!(dev = xf86I2CFindDev(pBus, 0x00A0))) { dev = xf86CreateI2CDevRec(); dev->DevName = "ddc2"; @@ -340,7 +304,6 @@ DDCRead_DDC2(int scrnIndex, I2CBusPtr pBus, int start, int len) dev->ByteTimeout = 2200; /* VESA DDC spec 3 p. 43 (+10 %) */ dev->StartTimeout = 550; dev->BitTimeout = 40; - dev->ByteTimeout = 40; dev->AcknTimeout = 40; dev->pI2CBus = pBus; diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am index c34ddd6e3..58099bce9 100644 --- a/hw/xfree86/dixmods/Makefile.am +++ b/hw/xfree86/dixmods/Makefile.am @@ -14,12 +14,23 @@ if DBE DBEMOD = libdbe.la endif -module_LTLIBRARIES = libafb.la \ - libcfb.la \ - libcfb32.la \ +if AFB +AFBMOD = libafb.la +endif + +if CFB +CFBMOD = libcfb.la libcfb32.la +endif + +if MFB +MFBMOD = libmfb.la +endif + +module_LTLIBRARIES = $(AFBMOD) \ + $(CFBMOD) \ libfb.la \ libwfb.la \ - libmfb.la \ + $(MFBMOD) \ libshadow.la extsmoduledir = $(moduledir)/extensions diff --git a/hw/xfree86/dixmods/extmod/dgaproc.h b/hw/xfree86/dixmods/extmod/dgaproc.h index 5e424afb2..aaea4e20c 100644 --- a/hw/xfree86/dixmods/extmod/dgaproc.h +++ b/hw/xfree86/dixmods/extmod/dgaproc.h @@ -120,8 +120,9 @@ int DGAGetOldDGAMode(int Index); int DGAGetModeInfo(int Index, XDGAModePtr mode, int num); Bool DGAVTSwitch(void); -Bool DGAStealMouseEvent(int Index, xEvent *e, int dx, int dy); -Bool DGAStealKeyEvent(int Index, xEvent *e); +Bool DGAStealButtonEvent(int Index, int button, int is_down); +Bool DGAStealMotionEvent(int Index, int dx, int dy); +Bool DGAStealKeyEvent(int Index, int key_code, int is_down); Bool DGAIsDgaEvent (xEvent *e); Bool DGADeliverEvent (ScreenPtr pScreen, xEvent *e); diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c index 401707abc..5384f434b 100644 --- a/hw/xfree86/dixmods/glxmodule.c +++ b/hw/xfree86/dixmods/glxmodule.c @@ -95,8 +95,8 @@ __glXMesaProxyScreenProbe(ScreenPtr pScreen) static __GLXprovider *provider; if (provider == NULL) { - GLcore = LoadSubModuleLocal(glxModule, "GLcore", NULL, NULL, NULL, NULL, - NULL, NULL); + GLcore = LoadSubModule(glxModule, "GLcore", NULL, NULL, NULL, NULL, + NULL, NULL); if (GLcore == NULL) return NULL; diff --git a/hw/xfree86/dixmods/xkbKillSrv.c b/hw/xfree86/dixmods/xkbKillSrv.c index 415873ad0..b3399db4a 100644 --- a/hw/xfree86/dixmods/xkbKillSrv.c +++ b/hw/xfree86/dixmods/xkbKillSrv.c @@ -40,7 +40,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "inputstr.h" #include "scrnintstr.h" #include "windowstr.h" -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> #include <X11/extensions/XI.h> #include "xf86.h" diff --git a/hw/xfree86/dixmods/xkbPrivate.c b/hw/xfree86/dixmods/xkbPrivate.c index e6d4f0fc0..e0cd21739 100644 --- a/hw/xfree86/dixmods/xkbPrivate.c +++ b/hw/xfree86/dixmods/xkbPrivate.c @@ -12,7 +12,7 @@ #include <X11/X.h> #include "windowstr.h" #define XKBSRV_NEED_FILE_FUNCS -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> #include "xf86.h" diff --git a/hw/xfree86/dixmods/xkbVT.c b/hw/xfree86/dixmods/xkbVT.c index a1cdc7016..e6d69e2eb 100644 --- a/hw/xfree86/dixmods/xkbVT.c +++ b/hw/xfree86/dixmods/xkbVT.c @@ -40,7 +40,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "inputstr.h" #include "scrnintstr.h" #include "windowstr.h" -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> #include <X11/extensions/XI.h> #include "xf86.h" diff --git a/hw/xfree86/doc/README.modes b/hw/xfree86/doc/README.modes new file mode 100644 index 000000000..894e21313 --- /dev/null +++ b/hw/xfree86/doc/README.modes @@ -0,0 +1,474 @@ + Multi-monitor Mode Setting APIs + Keith Packard, <keithp@keithp.com + 6 March 2007 + +1. Introduction + +This document describes a set of mode setting APIs added in X server version +1.3 that support multiple monitors per card. These interfaces expose the +underlying hardware CRTC and output concepts to the xf86 DDX layer so that +the implementation of initial server setup and mode changes through +extensions can be shared across drivers. In addition, these new interfaces +support a new configuration mechanism as well which allows each monitor to +be customized separately providing a consistent cross-driver configuration +mechanism that supports the full range of output features. + +All of the code implementing this interface can be found in hw/xfree86/modes +in the X server sources. + +2. Overview + +This document describes both the driver API and the configuration data +placed in xorg.conf; these are entirely separate as the driver has no +interaction with the configuration information at all. Much of the structure +here is cloned from the RandR extension version 1.2 additions which deal +with the same kinds of information. + +2.1 API overview + +The mode setting API is expressed through two new driver-visible objects, +the 'CRTC' (xf86CrtcRec) and the 'Output' (xf86OutputRec). A CRTC refers to +hardware within the video system that can scan a subset of the framebuffer +and generate a video signal. An Output receives that signal and transmits it +to a monitor, projector or other device. + +The xf86CrtcRec and xf86OutputRec contain a small amount of state data +related to the object along with a pointer to a set of functions provided by +the driver that manipulate the object in fairly simple ways. + +To emulate older behaviour, one of the outputs is picked as the 'compat' +output; this output changes over time as outputs are detected and used, the +goal is to always have one 'special' output which is used for operations +which need a single defined monitor (like XFree86-VidModeExtension mode +setting, RandR 1.1 mode setting, DDC property setting, etc.). + +2.1.1 Output overview + +As outputs are connected to monitors, they hold a list of modes supported by +the monitor. If the monitor and output support DDC, then the list of modes +generally comes from the EDID data in the monitor. Otherwise, the server +uses the standard VESA modes, pruned by monitor timing. If the configuration +file doesn't contain monitor timing data, the server uses default timing +information which supports 640x480, 800x600 and 1024x768 all with a 60Hz +refresh rate. + +As hardware often limits possible configuration combinations, each output +knows the set of CRTCs that it can be connected to as well as the set of +other outputs which can be simutaneously connected to a CRTC. + +2.1.2 CRTC overview + +CRTCs serve only to stream frame buffer data to outputs using a mode line. +Ideally, they would not be presented to the user at all, and in fact the +configuration file doesn't expose them. The RandR 1.2 protocol does, but the +hope there is that client-side applications will hide them carefully away. + +Each crtc has an associated cursor, along with the current configuration. +All of the data needed to determine valid configurations is contained within +the Outputs. + +2.2 Configuration overview + +As outputs drive monitors, the "Monitor" section has been repurposed to +define their configuration. This provides for a bit more syntax than +the large list of driver-specific options that were used in the past for +similar configuration. + +However, the existing "Monitor" section referenced by the active "Screen" +section no longer has any use at all; some sensible meaning for this +parameter is needed now that a Screen can have multiple Monitors. + +3. Public Functions + +3.1 PreInit functions + +These functions should be used during the driver PreInit phase, they are +arranged in the order they should be invoked. + + void + xf86CrtcConfigInit (ScrnInfoPtr scrn + const xf86CrtcConfigFuncsRec *funcs) + +This function allocates and initializes structures needed to track CRTC and +Output state. + + void + xf86CrtcSetSizeRange (ScrnInfoPtr scrn, + int minWidth, int minHeight, + int maxWidth, int maxHeight) + +This sets the range of screen sizes supported by the driver. + + xf86CrtcPtr + xf86CrtcCreate (ScrnInfoPtr scrn, + const xf86CrtcFuncsRec *funcs) + +Create one CRTC object. See the discussion below for a description of the +contents of the xf86CrtcFuncsRec. Note that this is done in PreInit, so it +should not be re-invoked at each server generation. Create one of these for +each CRTC present in the hardware. + + xf86OutputPtr + xf86OutputCreate (ScrnInfoPtr scrn, + const xf86OutputFuncsRec *funcs, + const char *name) + +Create one Output object. See the discussion below for a description of the +contents of the xf86OutputFuncsRec. This is also called from PreInit and +need not be re-invoked at each ScreenInit time. An Output should be created +for every Output present in the hardware, not just for outputs which have +detected monitors. + + Bool + xf86OutputRename (xf86OutputPtr output, const char *name) + +If necessary, the name of an output can be changed after it is created using +this function. + + Bool + xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow) + +Using the resources provided, and the configuration specified by the user, +this function computes an initial configuration for the server. It tries to +enable as much hardware as possible using some fairly simple heuristics. + +The 'canGrow' parameter indicates that the frame buffer does not have a fixed +size (fixed size frame buffers are required by XAA). When the frame buffer +has a fixed size, the configuration selects a 'reasonablely large' frame +buffer so that common reconfiguration options are possible. For resizable +frame buffers, the frame buffer is set to the smallest size that encloses +the desired configuration. + +3.2 ScreenInit functions + +These functions should be used during the driver ScreenInit phase. + + Bool + xf86DiDGAInit (ScreenPtr screen, unsigned long dga_address) + +This function provides driver-independent accelerated DGA support for some +of the DGA operations; using this, the driver can avoid needing to implement +any of the rest of DGA. + + Bool + xf86SaveScreen(ScreenPtr pScreen, int mode) + +Stick this in pScreen->SaveScreen and the core X screen saver will be +implemented by disabling outputs and crtcs using their dpms functions. + + void + xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags) + +Pass this function to xf86DPMSInit and all DPMS mode switching will be +managed by using the dpms functions provided by the Outputs and CRTCs. + + Bool + xf86CrtcScreenInit (ScreenPtr screen) + +This function completes the screen initialization process for the crtc and +output objects. Call it near the end of the ScreenInit function, after the +frame buffer and acceleration layers have been added. + +3.3 EnterVT functions + +Functions used during EnterVT, or whenever the current configuration needs +to be applied to the hardware. + + Bool + xf86SetDesiredModes (ScrnInfoPtr scrn) + +xf86InitialConfiguration selects the desired configuration at PreInit time; +when the server finally hits ScreenInit, xf86SetDesiredModes is used by the +driver to take that configuration and apply it to the hardware. In addition, +successful mode selection at other times updates the configuration that will +be used by this function, so LeaveVT/EnterVT pairs can simply invoke this +and return to the previous configuration. + +3.4 SwitchMode functions + +Functions called from the pScrn->SwitchMode hook, which is used by the +XFree86-VidModeExtension and the keypad mode switch commands. + + Bool + xf86SetSingleMode (ScrnInfoPtr scrn, + DisplayModePtr desired, + Rotation rotation) + +This function applies the specified mode to all active outputs. Which is to +say, it picks reasonable modes for all active outputs, attempting to get the +screen to the specified size while not breaking anything that is currently +working. + +3.7 get_modes functions + +Functions called during output->get_modes to help build lists of modes + + xf86MonPtr + xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus) + +This returns the EDID data structure for the 'output' using the I2C bus +'pDDCBus'. This has no effect on 'output' itself. + + void + xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon) + +Once the EDID data has been fetched, this call applies the EDID data to the +output object, setting the physical size and also various properties, like +the DDC root window property (when output is the 'compat' output), and the +RandR 1.2 EDID output properties. + + DisplayModePtr + xf86OutputGetEDIDModes (xf86OutputPtr output) + +Given an EDID data structure, this function computes a list of suitable +modes. This function also applies a sequence of 'quirks' during this process +so that the returned modes may not actually match the mode data present in +the EDID data. + +3.6 Other functions + +These remaining functions in the API can be used by the driver as needed. + + Bool + xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, + int x, int y) + +Applies a mode to a CRTC. All of the outputs which are currently using the +specified CRTC are included in the mode setting process. 'x' and 'y' are the +offset within the frame buffer that the crtc is placed at. No checking is +done in this function to ensure that the mode is usable by the active +outputs. + + void + xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY) + +This discards the mode lists for all outputs, re-detects monitor presence +and then acquires new mode lists for all monitors which are not disconnected. +Monitor configuration data is used to modify the mode lists returned by the +outputs. 'maxX' and 'maxY' limit the maximum size modes that will be +returned. + + void + xf86SetScrnInfoModes (ScrnInfoPtr pScrn) + +This copies the 'compat' output mode list into the pScrn modes list which is +used by the XFree86-VidModeExtension and the keypad mode switching +operations. The current 'desired' mode for the CRTC associated with the +'compat' output is placed first in this list to indicate the current mode. +Usually, the driver won't need to call this function as +xf86InitialConfiguration will do so automatically, as well as any RandR +functions which reprobe for modes. However, if the driver reprobes for modes +at other times using xf86ProbeOutputModes, this function needs to be called. + + Bool + xf86DiDGAReInit (ScreenPtr pScreen) + +This is similar to xf86SetScrnInfoModes, but it applies the 'compat' output +mode list to the set of modes advertised by the DGA extension; it needs to +be called whenever xf86ProbeOutputModes is invoked. + + void + xf86DisableUnusedFunctions(ScrnInfoPtr pScrn) + +After any sequence of calls using xf86CrtcSetMode, this function cleans up +any leftover Output and CRTC objects by disabling them, saving power. It is +safe to call this whenever the server is running as it only disables objects +which are not currently in use. + +4. CRTC operations + +4.1 CRTC functions + +These functions provide an abstract interface for the CRTC object; most +manipulation of the CRTC object is done through these functions. + + void + crtc->funcs->dpms (xf86CrtcPtr crtc, int mode) + +Where 'mode' is one of DPMSModeOff, DPMSModeSuspend, DPMSModeStandby or +DPMSModeOn. This requests that the crtc go to the specified power state. +When changing power states, the output dpms functions are invoked before the +crtc dpms functions. + + void + crtc->funcs->save (xf86CrtcPtr crtc) + + void + crtc->funcs->restore (xf86CrtcPtr crtc) + +Preserve/restore any register contents related to the CRTC. These are +strictly a convenience for the driver writer; if the existing driver has +fully operation save/restore functions, you need not place any additional +code here. In particular, the server itself never uses this function. + + Bool + crtc->funcs->lock (xf86CrtcPtr crtc) + + void + crtc->funcs->unlock (xf86CrtcPtr crtc) + +These functions are invoked around mode setting operations; the intent is +that DRI locking be done here to prevent DRI applications from manipulating +the hardware while the server is busy changing the output configuration. If +the lock function returns FALSE, the unlock function will not be invoked. + + Bool + crtc->funcs->mode_fixup (xf86CrtcPtr crtc, + DisplayModePtr mode, + DisplayModePtr adjusted_mode) + +This call gives the CRTC a chance to see what mode will be set and to +comment on the mode by changing 'adjusted_mode' as needed. This function +shall not modify the state of the crtc hardware at all. If the CRTC cannot +accept this mode, this function may return FALSE. + + void + crtc->funcs->prepare (xf86CrtcPtr crtc) + +This call is made just before the mode is set to make the hardware ready for +the operation. A usual function to perform here is to disable the crtc so +that mode setting can occur with clocks turned off and outputs deactivated. + + void + crtc->funcs->mode_set (xf86CrtcPtr crtc, + DisplayModePtr mode, + DisplayModePtr adjusted_mode) + +This function applies the specified mode (possibly adjusted by the CRTC +and/or Outputs). + + void + crtc->funcs->commit (xf86CrtcPtr crtc) + +Once the mode has been applied to the CRTC and Outputs, this function is +invoked to let the hardware turn things back on. + + void + crtc->funcs->gamma_set (xf86CrtcPtr crtc, CARD16 *red, + CARD16 *green, CARD16 *blue, int size) + +This function adjusts the gamma ramps for the specified crtc. + + void * + crtc->funcs->shadow_allocate (xf86CrtcPtr crtc, int width, int height) + +This function allocates frame buffer space for a shadow frame buffer. When +allocated, the crtc must scan from the shadow instead of the main frame +buffer. This is used for rotation. The address returned is passed to the +shadow_create function. This function should return NULL on failure. + + PixmapPtr + crtc->funcs->shadow_create (xf86CrtcPtr crtc, void *data, + int width, int height) + +This function creates a pixmap object that will be used as a shadow of the +main frame buffer for CRTCs which are rotated or reflected. 'data' is the +value returned by shadow_allocate. + + void + crtc->funcs->shadow_destroy (xf86CrtcPtr crtc, PixmapPtr pPixmap, + void *data) + +Destroys any associated shadow objects. If pPixmap is NULL, then a pixmap +was not created, but 'data' may still be non-NULL indicating that the shadow +had been allocated. + + void + crtc->funcs->destroy (xf86CrtcPtr crtc) + +When a CRTC is destroyed (which only happens in error cases), this function +can clean up any driver-specific data. + +4.2 CRTC fields + +The CRTC object is not opaque; there are several fields of interest to the +driver writer. + + struct _xf86Crtc { + /** + * Associated ScrnInfo + */ + ScrnInfoPtr scrn; + + /** + * Active state of this CRTC + * + * Set when this CRTC is driving one or more outputs + */ + Bool enabled; + + /** Track whether cursor is within CRTC range */ + Bool cursorInRange; + + /** Track state of cursor associated with this CRTC */ + Bool cursorShown; + + /** + * Active mode + * + * This reflects the mode as set in the CRTC currently + * It will be cleared when the VT is not active or + * during server startup + */ + DisplayModeRec mode; + Rotation rotation; + PixmapPtr rotatedPixmap; + void *rotatedData; + + /** + * Position on screen + * + * Locates this CRTC within the frame buffer + */ + int x, y; + + /** + * Desired mode + * + * This is set to the requested mode, independent of + * whether the VT is active. In particular, it receives + * the startup configured mode and saves the active mode + * on VT switch. + */ + DisplayModeRec desiredMode; + Rotation desiredRotation; + int desiredX, desiredY; + + /** crtc-specific functions */ + const xf86CrtcFuncsRec *funcs; + + /** + * Driver private + * + * Holds driver-private information + */ + void *driver_private; + #ifdef RANDR_12_INTERFACE + /** + * RandR crtc + * + * When RandR 1.2 is available, this + * points at the associated crtc object + */ + RRCrtcPtr randr_crtc; + #else + void *randr_crtc; + #endif + }; + + +5. Output functions. + +6. Configuration + +Because the configuration file syntax is fixed, +this was done by creating new "Driver" section options that hook specific +outputs to specific "Monitor" sections in the file. The option: +section of the form: + + Option "monitor-VGA" "My VGA Monitor" + +connects the VGA output of this driver to the "Monitor" section with +Identifier "My VGA Monitor". All of the usual monitor options can now be +placed in that "Monitor" section and will be applied to the VGA output +configuration. diff --git a/hw/xfree86/doc/man/xorg.conf.man.pre b/hw/xfree86/doc/man/xorg.conf.man.pre index bbba21112..cc60d0754 100644 --- a/hw/xfree86/doc/man/xorg.conf.man.pre +++ b/hw/xfree86/doc/man/xorg.conf.man.pre @@ -1004,12 +1004,22 @@ The .B Identifier entry specifies the unique name for this monitor. The .B Monitor -section provides information about the specifications of the monitor, -monitor-specific +section may be used to provide information about the specifications of the +monitor, monitor-specific .BR Options , -and information about the video modes to use with the monitor. Specifying -video modes is optional because the server now has a built-in list of -VESA standard modes. When modes are specified explicitly in the +and information about the video modes to use with the monitor. +.PP +With RandR 1.2-enabled drivers, monitor sections are tied to specific outputs +of the video card. Each output has a name, and the server will look for a +Monitor named +.B \*qMonitor-outputname\*q +for configuration of that output (for example, +.B \*qMonitor-VGA\*q +for a VGA output) +.PP +Specifying video modes is optional because the server will use the DDC or other +information provided by the monitor to automatically configure the list of +modes available. When modes are specified explicitly in the .B Monitor section (with the .BR Modes , @@ -1017,7 +1027,8 @@ section (with the or .B UseModes keywords), built-in modes with the same names are not included. Built-in -modes with different names are, however, still implicitly included. +modes with different names are, however, still implicitly included, when they +meet the requirements of the monitor. .PP The entries that may be used in .B Monitor @@ -1214,6 +1225,62 @@ monitors do not require it. The default is off. This optional entry specifies the vertical refresh rate that the server should aim for when selecting video modes. Without this option, the default is to prefer modes with higher refresh rates. +.TP 7 +.BI "Option " "\*qPreferredMode\*q " \*qstring\*q +This optional entry specifies a mode to be marked as the preferred initial mode +of the monitor. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qPosition\*q " "\*qx y\*q" +This optional entry specifies the position of the monitor within the X +screen. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qLeftOf\*q " \*qmonitor\*q +This optional entry specifies that the monitor should be positioned to the +left of the monitor of the given name. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qRightOf\*q " \*qmonitor\*q +This optional entry specifies that the monitor should be positioned to the +right of the monitor of the given name. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qAbove\*q " \*qmonitor\*q +This optional entry specifies that the monitor should be positioned above the +monitor of the given name. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qBelow\*q " \*qmonitor\*q +This optional entry specifies that the monitor should be positioned below the +monitor of the given name. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qEnable\*q " \*qbool\*q +This optional entry specifies whether the monitor should be turned on +at startup. By default, the server will attempt to enable all connected +monitors. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qMinClock\*q " \*qfrequency\*q +This optional entry specifies the minimum dot clock, in kHz, that is supported +by the monitor. +.TP 7 +.BI "Option " "\*qMaxClock\*q " \*qfrequency\*q +This optional entry specifies the maximum dot clock, in kHz, that is supported +by the monitor. +.TP 7 +.BI "Option " "\*qIgnore\*q " \*qbool\*q +This optional entry specifies that the monitor should be ignored entirely, +and not reported through RandR. This is useful if the hardware reports the +presence of outputs that don't exist. +(RandR 1.2-supporting drivers only) +.TP 7 +.BI "Option " "\*qRotate\*q " \*qrotation\*q +This optional entry specifies the initial rotation of the given monitor. +Valid values for rotation are \*qnormal\*q, \*qleft\*q, \*qright\*q, and +\*qinverted\*q. +(RandR 1.2-supporting drivers only) .SH MODES SECTION The config file may have multiple diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c index e9cf27c96..a9ca4cc80 100644 --- a/hw/xfree86/dri/dri.c +++ b/hw/xfree86/dri/dri.c @@ -71,6 +71,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "mipointer.h" #include "xf86_OSproc.h" +#define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu) + #if !defined(PANORAMIX) extern Bool noPanoramiXExtension; #endif @@ -204,6 +206,7 @@ DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD) pDRIPriv->directRenderingSupport = TRUE; pDRIPriv->pDriverInfo = pDRIInfo; pDRIPriv->nrWindows = 0; + pDRIPriv->nrWindowsVisible = 0; pDRIPriv->fullscreen = NULL; pDRIPriv->createDummyCtx = pDRIInfo->createDummyCtx; @@ -1006,6 +1009,93 @@ DRITransitionTo2d(ScreenPtr pScreen) } +static int +DRIDCNTreeTraversal(WindowPtr pWin, pointer data) +{ + DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin); + + if (pDRIDrawablePriv) { + ScreenPtr pScreen = pWin->drawable.pScreen; + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + + if (REGION_NUM_RECTS(&pWin->clipList) > 0) { + WindowPtr *pDRIWindows = (WindowPtr*)data; + int i = 0; + + while (pDRIWindows[i]) + i++; + + pDRIWindows[i] = pWin; + + pDRIPriv->nrWalked++; + } + + if (pDRIPriv->nrWindows == pDRIPriv->nrWalked) + return WT_STOPWALKING; + } + + return WT_WALKCHILDREN; +} + +static void +DRIDriverClipNotify(ScreenPtr pScreen) +{ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + + if (pDRIPriv->pDriverInfo->ClipNotify) { + WindowPtr *pDRIWindows = xcalloc(sizeof(WindowPtr), pDRIPriv->nrWindows); + DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo; + + if (pDRIPriv->nrWindows > 0) { + pDRIPriv->nrWalked = 0; + TraverseTree(WindowTable[pScreen->myNum], DRIDCNTreeTraversal, + (pointer)pDRIWindows); + } + + pDRIInfo->ClipNotify(pScreen, pDRIWindows, pDRIPriv->nrWindows); + + xfree(pDRIWindows); + } +} + +static void +DRIIncreaseNumberVisible(ScreenPtr pScreen) +{ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + + switch (++pDRIPriv->nrWindowsVisible) { + case 1: + DRITransitionTo3d( pScreen ); + break; + case 2: + DRITransitionToSharedBuffers( pScreen ); + break; + default: + break; + } + + DRIDriverClipNotify(pScreen); +} + +static void +DRIDecreaseNumberVisible(ScreenPtr pScreen) +{ + DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen); + + switch (--pDRIPriv->nrWindowsVisible) { + case 0: + DRITransitionTo2d( pScreen ); + break; + case 1: + DRITransitionToPrivateBuffers( pScreen ); + break; + default: + break; + } + + DRIDriverClipNotify(pScreen); +} + Bool DRICreateDrawable(ScreenPtr pScreen, Drawable id, DrawablePtr pDrawable, drm_drawable_t * hHWDrawable) @@ -1040,21 +1130,16 @@ DRICreateDrawable(ScreenPtr pScreen, Drawable id, pDRIDrawablePriv->pScreen = pScreen; pDRIDrawablePriv->refCount = 1; pDRIDrawablePriv->drawableIndex = -1; + pDRIDrawablePriv->nrects = REGION_NUM_RECTS(&pWin->clipList); /* save private off of preallocated index */ pWin->devPrivates[DRIWindowPrivIndex].ptr = (pointer)pDRIDrawablePriv; - switch (++pDRIPriv->nrWindows) { - case 1: - DRITransitionTo3d( pScreen ); - break; - case 2: - DRITransitionToSharedBuffers( pScreen ); - break; - default: - break; - } + pDRIPriv->nrWindows++; + + if (pDRIDrawablePriv->nrects) + DRIIncreaseNumberVisible(pScreen); /* track this in case this window is destroyed */ AddResource(id, DRIDrawablePrivResType, (pointer)pWin); @@ -1126,19 +1211,14 @@ DRIDrawablePrivDelete(pointer pResource, XID id) pDRIDrawablePriv->hwDrawable)) { return FALSE; } + xfree(pDRIDrawablePriv); pWin->devPrivates[DRIWindowPrivIndex].ptr = NULL; - switch (--pDRIPriv->nrWindows) { - case 0: - DRITransitionTo2d( pDrawable->pScreen ); - break; - case 1: - DRITransitionToPrivateBuffers( pDrawable->pScreen ); - break; - default: - break; - } + pDRIPriv->nrWindows--; + + if (REGION_NUM_RECTS(&pWin->clipList)) + DRIDecreaseNumberVisible(pDrawable->pScreen); } else { /* pixmap (or for GLX 1.3, a PBuffer) */ /* NOT_DONE */ @@ -1276,7 +1356,7 @@ DRIGetDrawableInfo(ScreenPtr pScreen, *backX = *X; *backY = *Y; - if (pDRIPriv->nrWindows == 1 && *numClipRects) { + if (pDRIPriv->nrWindowsVisible == 1 && *numClipRects) { /* Use a single cliprect. */ int x0 = *X; @@ -1652,7 +1732,7 @@ DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) if(!pDRIPriv) return; - if(pDRIPriv->nrWindows > 0) { + if(pDRIPriv->nrWindowsVisible > 0) { RegionRec reg; REGION_NULL(pScreen, ®); @@ -1844,19 +1924,28 @@ DRIClipNotify(WindowPtr pWin, int dx, int dy) if(!pDRIPriv) return; if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) { + int nrects = REGION_NUM_RECTS(&pWin->clipList); if(!pDRIPriv->windowsTouched) { DRILockTree(pScreen); pDRIPriv->windowsTouched = TRUE; } + if (nrects && !pDRIDrawablePriv->nrects) + DRIIncreaseNumberVisible(pScreen); + else if (!nrects && pDRIDrawablePriv->nrects) + DRIDecreaseNumberVisible(pScreen); + else + DRIDriverClipNotify(pScreen); + + pDRIDrawablePriv->nrects = nrects; + pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp = DRIDrawableValidationStamp++; drmUpdateDrawableInfo(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable, DRM_DRAWABLE_CLIPRECTS, - REGION_NUM_RECTS(&pWin->clipList), - REGION_RECTS(&pWin->clipList)); + nrects, REGION_RECTS(&pWin->clipList)); } /* call lower wrapped functions */ diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h index 0d695344b..395b4f1b3 100644 --- a/hw/xfree86/dri/dri.h +++ b/hw/xfree86/dri/dri.h @@ -109,7 +109,7 @@ typedef struct { */ #define DRIINFO_MAJOR_VERSION 5 -#define DRIINFO_MINOR_VERSION 0 +#define DRIINFO_MINOR_VERSION 1 #define DRIINFO_PATCH_VERSION 0 typedef struct { @@ -175,6 +175,9 @@ typedef struct { /* New with DRI version 4.1.0 */ void (*TransitionSingleToMulti3D)(ScreenPtr pScreen); void (*TransitionMultiToSingle3D)(ScreenPtr pScreen); + + /* New with DRI version 5.1.0 */ + void (*ClipNotify)(ScreenPtr pScreen, WindowPtr *ppWin, int num); } DRIInfoRec, *DRIInfoPtr; diff --git a/hw/xfree86/dri/dristruct.h b/hw/xfree86/dri/dristruct.h index 340c59a2e..9c42ff9cc 100644 --- a/hw/xfree86/dri/dristruct.h +++ b/hw/xfree86/dri/dristruct.h @@ -53,6 +53,7 @@ typedef struct _DRIDrawablePrivRec int drawableIndex; ScreenPtr pScreen; int refCount; + int nrects; } DRIDrawablePrivRec, *DRIDrawablePrivPtr; struct _DRIContextPrivRec @@ -87,6 +88,8 @@ typedef struct _DRIScreenPrivRec void** partial3DContextStore; /* parital 3D context */ DRIInfoPtr pDriverInfo; int nrWindows; + int nrWindowsVisible; + int nrWalked; drm_clip_rect_t private_buffer_rect; /* management of private buffers */ DrawablePtr fullscreen; /* pointer to fullscreen drawable */ drm_clip_rect_t fullscreen_rect; /* fake rect for fullscreen mode */ diff --git a/hw/xfree86/i2c/Makefile.am b/hw/xfree86/i2c/Makefile.am index e73fcaeb8..a16d88071 100644 --- a/hw/xfree86/i2c/Makefile.am +++ b/hw/xfree86/i2c/Makefile.am @@ -1,4 +1,4 @@ -module_LTLIBRARIES = libi2c.la +noinst_LIBRARIES = libi2c.a multimediadir = $(moduledir)/multimedia multimedia_LTLIBRARIES = \ @@ -10,8 +10,7 @@ multimedia_LTLIBRARIES = \ tda9885_drv.la \ uda1380_drv.la -libi2c_la_LDFLAGS = -avoid-version -libi2c_la_SOURCES = xf86i2c.c xf86i2cmodule.c +libi2c_a_SOURCES = xf86i2c.c INCLUDES = $(XORG_INCS) diff --git a/hw/xfree86/i2c/uda1380_module.c b/hw/xfree86/i2c/uda1380_module.c index 384458326..895f8c6f2 100644 --- a/hw/xfree86/i2c/uda1380_module.c +++ b/hw/xfree86/i2c/uda1380_module.c @@ -12,7 +12,7 @@ static XF86ModuleVersionInfo uda1380VersRec = MODULEVENDORSTRING, MODINFOSTRING1, MODINFOSTRING2, - XF86_VERSION_CURRENT, + XORG_VERSION_CURRENT, 1, 0, 0, ABI_CLASS_VIDEODRV, /* This needs the video driver ABI */ ABI_VIDEODRV_VERSION, diff --git a/hw/xfree86/i2c/xf86i2cmodule.c b/hw/xfree86/i2c/xf86i2cmodule.c deleted file mode 100644 index 3c6d313c7..000000000 --- a/hw/xfree86/i2c/xf86i2cmodule.c +++ /dev/null @@ -1,36 +0,0 @@ -/* (c) Itai Nahshon - * - * This code is derived from and inspired by the I2C driver - * from the Linux kernel. - * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> - */ - -#ifdef HAVE_XORG_CONFIG_H -#include <xorg-config.h> -#endif - -#include "xf86Module.h" - -static MODULESETUPPROTO(i2cSetup); - -static XF86ModuleVersionInfo i2cVersRec = -{ - "i2c", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 1, 2, 0, - ABI_CLASS_VIDEODRV, /* This needs the video driver ABI */ - ABI_VIDEODRV_VERSION, - MOD_CLASS_NONE, - {0,0,0,0} -}; - -_X_EXPORT XF86ModuleData i2cModuleData = { &i2cVersRec, i2cSetup, NULL }; - -static pointer -i2cSetup(pointer module, pointer opts, int *errmaj, int *errmin) { -/* ErrorF("i2cSetup\n"); */ - return (pointer)1; -} diff --git a/hw/xfree86/loader/Makefile.am b/hw/xfree86/loader/Makefile.am index 206600214..ef9ab9ab3 100644 --- a/hw/xfree86/loader/Makefile.am +++ b/hw/xfree86/loader/Makefile.am @@ -2,7 +2,8 @@ noinst_LIBRARIES = libloader.a INCLUDES = $(XORG_INCS) -I$(srcdir)/../parser -I$(srcdir)/../dixmods/extmod \ -I$(srcdir)/../vbe -I$(top_srcdir)/miext/cw -I$(srcdir)/../int10 \ - -I$(srcdir)/../ddc -I$(srcdir)/../i2c + -I$(srcdir)/../ddc -I$(srcdir)/../i2c -I$(srcdir)/../modes \ + -I$(srcdir)/../ramdac #AM_LDFLAGS = -r AM_CFLAGS = -DIN_LOADER $(DIX_CFLAGS) $(XORG_CFLAGS) diff --git a/hw/xfree86/loader/dixsym.c b/hw/xfree86/loader/dixsym.c index 32e0e4f68..5d06b05c7 100644 --- a/hw/xfree86/loader/dixsym.c +++ b/hw/xfree86/loader/dixsym.c @@ -86,7 +86,7 @@ #endif #include "selection.h" #ifdef XKB -#include <X11/extensions/XKBsrv.h> +#include <xkbsrv.h> extern int XkbDfltRepeatDelay, XkbDfltRepeatInterval; #endif @@ -271,10 +271,8 @@ _X_HIDDEN void *dixLookupTab[] = { SYMFUNC(AllocateColormapPrivateIndex) SYMFUNC(AllocateDevicePrivateIndex) SYMFUNC(AllocateDevicePrivate) -#ifdef PIXPRIV SYMFUNC(AllocatePixmapPrivateIndex) SYMFUNC(AllocatePixmapPrivate) -#endif /* resource.c */ SYMFUNC(AddResource) SYMFUNC(ChangeResourceValue) diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c index ddd624c2a..774a4c4a0 100644 --- a/hw/xfree86/loader/loader.c +++ b/hw/xfree86/loader/loader.c @@ -189,101 +189,6 @@ _LoaderListPop(int handle) return 0; } -/* - * _LoaderHandleToName() will return the name of the first module with a - * given handle. This requires getting the last module on the LIFO with - * the given handle. - */ -char * -_LoaderHandleToName(int handle) -{ - loaderPtr item = listHead; - loaderPtr aritem = NULL; - loaderPtr lastitem = NULL; - - if (handle < 0) { - return "(built-in)"; - } - while (item) { - if (item->handle == handle) { - if (strchr(item->name, ':') == NULL) - aritem = item; - else - lastitem = item; - } - item = item->next; - } - - if (aritem) - return aritem->name; - - if (lastitem) - return lastitem->name; - - return 0; -} - -/* - * _LoaderHandleToCanonicalName() will return the cname of the first module - * with a given handle. This requires getting the last module on the LIFO with - * the given handle. - */ -char * -_LoaderHandleToCanonicalName(int handle) -{ - loaderPtr item = listHead; - loaderPtr lastitem = NULL; - - if (handle < 0) { - return "(built-in)"; - } - while (item) { - if (item->handle == handle) { - lastitem = item; - } - item = item->next; - } - - if (lastitem) - return lastitem->cname; - - return NULL; -} - -/* - * _LoaderModuleToName() will return the name of the first module with a - * given handle. This requires getting the last module on the LIFO with - * the given handle. - */ -char * -_LoaderModuleToName(int module) -{ - loaderPtr item = listHead; - loaderPtr aritem = NULL; - loaderPtr lastitem = NULL; - - if (module < 0) { - return "(built-in)"; - } - while (item) { - if (item->module == module) { - if (strchr(item->name, ':') == NULL) - aritem = item; - else - lastitem = item; - } - item = item->next; - } - - if (aritem) - return aritem->name; - - if (lastitem) - return lastitem->name; - - return 0; -} - /* These four are just ABI stubs */ _X_EXPORT void LoaderRefSymbols(const char *sym0, ...) @@ -450,35 +355,14 @@ LoaderUnload(int handle) return 0; } -void -LoaderDuplicateSymbol(const char *symbol, const int handle) -{ - ErrorF("Duplicate symbol %s in %s\n", symbol, - listHead ? listHead->name : "(built-in)"); - ErrorF("Also defined in %s\n", _LoaderHandleToName(handle)); - FatalError("Module load failure\n"); -} - unsigned long LoaderOptions = 0; void -LoaderResetOptions(void) -{ - LoaderOptions = 0; -} - -void LoaderSetOptions(unsigned long opts) { LoaderOptions |= opts; } -void -LoaderClearOptions(unsigned long opts) -{ - LoaderOptions &= ~opts; -} - _X_EXPORT int LoaderGetABIVersion(const char *abiclass) { diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h index ecbd6762d..b71ad4590 100644 --- a/hw/xfree86/loader/loaderProcs.h +++ b/hw/xfree86/loader/loaderProcs.h @@ -97,9 +97,6 @@ void LoadFont(FontModule *); void UnloadModule(ModuleDescPtr); void UnloadSubModule(ModuleDescPtr); void UnloadDriver(ModuleDescPtr); -void FreeModuleDesc(ModuleDescPtr mod); -ModuleDescPtr NewModuleDesc(const char *); -ModuleDescPtr AddSibling(ModuleDescPtr head, ModuleDescPtr new); void LoaderSetPath(const char *path); void LoaderSortExtensions(void); @@ -108,7 +105,6 @@ unsigned long LoaderGetModuleVersion(ModuleDescPtr mod); void LoaderResetOptions(void); void LoaderSetOptions(unsigned long); -void LoaderClearOptions(unsigned long); /* Options for LoaderSetOptions */ #define LDR_OPT_ABI_MISMATCH_NONFATAL 0x0001 diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index ec0f181db..db12da466 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -745,6 +745,13 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data, return TRUE; } +static ModuleDescPtr +AddSibling(ModuleDescPtr head, ModuleDescPtr new) +{ + new->sib = head; + return (new); +} + _X_EXPORT ModuleDescPtr LoadSubModule(ModuleDescPtr parent, const char *module, const char **subdirlist, const char **patternlist, @@ -768,42 +775,35 @@ LoadSubModule(ModuleDescPtr parent, const char *module, submod = doLoadModule(module, NULL, subdirlist, patternlist, options, modreq, errmaj, errmin, LD_FLAG_GLOBAL); - if (submod) { + if (submod && submod != (ModuleDescPtr) 1) { parent->child = AddSibling(parent->child, submod); submod->parent = parent; } return submod; } -ModuleDescPtr -LoadSubModuleLocal(ModuleDescPtr parent, const char *module, - const char **subdirlist, const char **patternlist, - pointer options, const XF86ModReqInfo * modreq, - int *errmaj, int *errmin) +static ModuleDescPtr +NewModuleDesc(const char *name) { - ModuleDescPtr submod; - - xf86MsgVerb(X_INFO, 3, "Loading local sub module \"%s\"\n", module); + ModuleDescPtr mdp = xalloc(sizeof(ModuleDesc)); - if (PathIsAbsolute(module)) - { - xf86Msg(X_ERROR, - "LoadSubModule: Absolute module path not permitted: \"%s\"\n", - module); - if (errmaj) - *errmaj = LDR_BADUSAGE; - if (errmin) - *errmin = 0; - return NULL; + if (mdp) { + mdp->child = NULL; + mdp->sib = NULL; + mdp->parent = NULL; + mdp->demand_next = NULL; + mdp->name = xstrdup(name); + mdp->filename = NULL; + mdp->identifier = NULL; + mdp->client_id = 0; + mdp->in_use = 0; + mdp->handle = -1; + mdp->SetupProc = NULL; + mdp->TearDownProc = NULL; + mdp->TearDownData = NULL; } - submod = doLoadModule(module, NULL, subdirlist, patternlist, options, - modreq, errmaj, errmin, 0); - if (submod) { - parent->child = AddSibling(parent->child, submod); - submod->parent = parent; - } - return submod; + return (mdp); } _X_EXPORT ModuleDescPtr @@ -838,6 +838,12 @@ DuplicateModule(ModuleDescPtr mod, ModuleDescPtr parent) return ret; } +static const char *compiled_in_modules[] = { + "ddc", + "i2c", + "ramdac", + NULL +}; static ModuleDescPtr doLoadModule(const char *module, const char *path, const char **subdirlist, @@ -856,9 +862,17 @@ doLoadModule(const char *module, const char *path, const char **subdirlist, PatternPtr patterns = NULL; int noncanonical = 0; char *m = NULL; + const char **cim; xf86MsgVerb(X_INFO, 3, "LoadModule: \"%s\"", module); + for (cim = compiled_in_modules; *cim; cim++) + if (!strcmp (module, *cim)) + { + xf86MsgVerb(X_INFO, 3, "Module already built-in\n"); + return (ModuleDescPtr) 1; + } + patterns = InitPatterns(patternlist); name = LoaderGetCanonicalName(module, patterns); noncanonical = (name && strcmp(module, name) != 0); @@ -1085,29 +1099,18 @@ LoadModule(const char *module, const char *path, const char **subdirlist, modreq, errmaj, errmin, LD_FLAG_GLOBAL); } -ModuleDescPtr -LoadDriver(const char *module, const char *path, int handle, pointer options, - int *errmaj, int *errmin) -{ - return LoadModule(module, path, NULL, NULL, options, NULL, errmaj, - errmin); -} - void UnloadModule(ModuleDescPtr mod) { UnloadModuleOrDriver(mod); } -void -UnloadDriver(ModuleDescPtr mod) -{ - UnloadModuleOrDriver(mod); -} - static void UnloadModuleOrDriver(ModuleDescPtr mod) { + if (mod == (ModuleDescPtr) 1) + return; + if (mod == NULL || mod->name == NULL) return; @@ -1151,14 +1154,16 @@ UnloadSubModule(ModuleDescPtr mod) xfree(mod); } -void +static void FreeModuleDesc(ModuleDescPtr head) { ModuleDescPtr sibs, prev; + if (head == (ModuleDescPtr) 1) + return; /* * only free it if it's not marked as in use. In use means that it may - * be unloaded someday, and UnloadModule or UnloadDriver will free it + * be unloaded someday, and UnloadModule will free it */ if (head->in_use) return; @@ -1173,38 +1178,6 @@ FreeModuleDesc(ModuleDescPtr head) } } -ModuleDescPtr -NewModuleDesc(const char *name) -{ - ModuleDescPtr mdp = xalloc(sizeof(ModuleDesc)); - - if (mdp) { - mdp->child = NULL; - mdp->sib = NULL; - mdp->parent = NULL; - mdp->demand_next = NULL; - mdp->name = xstrdup(name); - mdp->filename = NULL; - mdp->identifier = NULL; - mdp->client_id = 0; - mdp->in_use = 0; - mdp->handle = -1; - mdp->SetupProc = NULL; - mdp->TearDownProc = NULL; - mdp->TearDownData = NULL; - } - - return (mdp); -} - -ModuleDescPtr -AddSibling(ModuleDescPtr head, ModuleDescPtr new) -{ - new->sib = head; - return (new); - -} - static void RemoveChild(ModuleDescPtr child) { @@ -1338,7 +1311,7 @@ LoaderGetCanonicalName(const char *modname, PatternPtr patterns) unsigned long LoaderGetModuleVersion(ModuleDescPtr mod) { - if (!mod || !mod->VersionInfo) + if (!mod || mod == (ModuleDescPtr) 1 || !mod->VersionInfo) return 0; return MODULE_VERSION_NUMERIC(mod->VersionInfo->majorversion, diff --git a/hw/xfree86/loader/misym.c b/hw/xfree86/loader/misym.c index 46d6a024d..78ae10e02 100644 --- a/hw/xfree86/loader/misym.c +++ b/hw/xfree86/loader/misym.c @@ -208,9 +208,6 @@ _X_HIDDEN void *miLookupTab[] = { #ifdef RENDER SYMFUNC(miGlyphExtents) #endif -#ifdef COMPOSITE - SYMFUNC(miDisableCompositeWrapper) -#endif #ifdef DAMAGE SYMFUNC(DamageDamageRegion) #endif diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c index 952e7fe15..1900e00af 100644 --- a/hw/xfree86/loader/xf86sym.c +++ b/hw/xfree86/loader/xf86sym.c @@ -87,6 +87,13 @@ #include "xf86sbusBus.h" #endif #include "compiler.h" +#include "xf86Crtc.h" +#include "xf86Modes.h" +#ifdef RANDR +#include "xf86RandR12.h" +#endif +#include "xf86DDC.h" +#include "edid.h" #ifndef HAS_GLIBC_SIGSETJMP #if defined(setjmp) && defined(__GNU_LIBRARY__) && \ @@ -1132,4 +1139,91 @@ _X_HIDDEN void *xfree86LookupTab[] = { /* Pci.c */ SYMVAR(pciNumBuses) + + /* modes */ + SYMVAR(xf86CrtcConfigPrivateIndex) + SYMFUNC(xf86CrtcConfigInit) + SYMFUNC(xf86CrtcConfigPrivateIndex) + SYMFUNC(xf86CrtcCreate) + SYMFUNC(xf86CrtcDestroy) + SYMFUNC(xf86CrtcInUse) + SYMFUNC(xf86CrtcRotate) + SYMFUNC(xf86CrtcSetMode) + SYMFUNC(xf86CrtcSetSizeRange) + SYMFUNC(xf86CVTMode) + SYMFUNC(xf86DisableUnusedFunctions) + SYMFUNC(xf86DPMSSet) + SYMFUNC(xf86DuplicateMode) + SYMFUNC(xf86DuplicateModes) + SYMFUNC(xf86GetDefaultModes) + SYMFUNC(xf86GetMonitorModes) + SYMFUNC(xf86InitialConfiguration) + SYMFUNC(xf86ModeHSync) + SYMFUNC(xf86ModesAdd) + SYMFUNC(xf86ModesEqual) + SYMFUNC(xf86ModeVRefresh) + SYMFUNC(xf86OutputCreate) + SYMFUNC(xf86OutputDestroy) + SYMFUNC(xf86OutputGetEDID) + SYMFUNC(xf86OutputGetEDIDModes) + SYMFUNC(xf86OutputRename) + SYMFUNC(xf86OutputSetEDID) + SYMFUNC(xf86PrintModeline) + SYMFUNC(xf86ProbeOutputModes) + SYMFUNC(xf86PruneInvalidModes) + SYMFUNC(xf86SetModeCrtc) + SYMFUNC(xf86SetModeDefaultName) + SYMFUNC(xf86SetScrnInfoModes) + SYMFUNC(xf86ValidateModesClocks) + SYMFUNC(xf86ValidateModesFlags) + SYMFUNC(xf86ValidateModesSize) + SYMFUNC(xf86ValidateModesSync) + SYMFUNC(xf86ValidateModesUserConfig) + SYMFUNC(xf86DiDGAInit) + SYMFUNC(xf86DiDGAReInit) + SYMFUNC(xf86DDCGetModes) + SYMFUNC(xf86SaveScreen) +#ifdef RANDR + SYMFUNC(xf86RandR12CreateScreenResources) + SYMFUNC(xf86RandR12GetOriginalVirtualSize) + SYMFUNC(xf86RandR12GetRotation) + SYMFUNC(xf86RandR12Init) + SYMFUNC(xf86RandR12PreInit) + SYMFUNC(xf86RandR12SetConfig) + SYMFUNC(xf86RandR12SetRotations) +#endif + SYMFUNC(xf86_cursors_init) + SYMFUNC(xf86_reload_cursors) + SYMFUNC(xf86_show_cursors) + SYMFUNC(xf86_hide_cursors) + SYMFUNC(xf86_cursors_fini) + + SYMFUNC(xf86DoEDID_DDC1) + SYMFUNC(xf86DoEDID_DDC2) + SYMFUNC(xf86InterpretEDID) + SYMFUNC(xf86PrintEDID) + SYMFUNC(xf86InterpretVdif) + SYMFUNC(xf86print_vdif) + SYMFUNC(xf86DDCMonitorSet) + SYMFUNC(xf86SetDDCproperties) + + SYMFUNC(xf86CreateI2CBusRec) + SYMFUNC(xf86CreateI2CDevRec) + SYMFUNC(xf86DestroyI2CBusRec) + SYMFUNC(xf86DestroyI2CDevRec) + SYMFUNC(xf86I2CBusInit) + SYMFUNC(xf86I2CDevInit) + SYMFUNC(xf86I2CFindBus) + SYMFUNC(xf86I2CFindDev) + SYMFUNC(xf86I2CGetScreenBuses) + SYMFUNC(xf86I2CProbeAddress) + SYMFUNC(xf86I2CReadByte) + SYMFUNC(xf86I2CReadBytes) + SYMFUNC(xf86I2CReadStatus) + SYMFUNC(xf86I2CReadWord) + SYMFUNC(xf86I2CWriteByte) + SYMFUNC(xf86I2CWriteBytes) + SYMFUNC(xf86I2CWriteRead) + SYMFUNC(xf86I2CWriteVec) + SYMFUNC(xf86I2CWriteWord) }; diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am new file mode 100644 index 000000000..1f82068b3 --- /dev/null +++ b/hw/xfree86/modes/Makefile.am @@ -0,0 +1,29 @@ +noinst_LIBRARIES = libxf86modes.a + +libxf86modes_a_SOURCES = \ + xf86Crtc.c \ + xf86Crtc.h \ + xf86Cursors.c \ + xf86cvt.c \ + xf86DiDGA.c \ + xf86EdidModes.c \ + xf86Modes.c \ + xf86Modes.h \ + xf86RandR12.c \ + xf86RandR12.h \ + xf86Rename.h \ + xf86Rotate.c + +INCLUDES = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c \ + -I$(srcdir)/../loader -I$(srcdir)/../rac -I$(srcdir)/../parser \ + -I$(srcdir)/../scanpci -I$(srcdir)/../vbe -I$(srcdir)/../int10 \ + -I$(srcdir)/../vgahw -I$(srcdir)/../ramdac \ + -I$(srcdir)/../dixmods/extmod + +sdk_HEADERS = \ + xf86Crtc.h \ + xf86Modes.h \ + xf86RandR12.h \ + xf86Rename.h + +AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c new file mode 100644 index 000000000..7d86b6606 --- /dev/null +++ b/hw/xfree86/modes/xf86Crtc.c @@ -0,0 +1,2040 @@ +/* + * 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include <stddef.h> +#include <string.h> +#include <stdio.h> + +#include "xf86.h" +#include "xf86DDC.h" +#include "xf86Crtc.h" +#include "xf86Modes.h" +#include "xf86RandR12.h" +#include "X11/extensions/render.h" +#define DPMS_SERVER +#include "X11/extensions/dpms.h" +#include "X11/Xatom.h" +#ifdef RENDER +#include "picturestr.h" +#endif + +/* + * Initialize xf86CrtcConfig structure + */ + +int xf86CrtcConfigPrivateIndex = -1; + +void +xf86CrtcConfigInit (ScrnInfoPtr scrn, + const xf86CrtcConfigFuncsRec *funcs) +{ + xf86CrtcConfigPtr config; + + if (xf86CrtcConfigPrivateIndex == -1) + xf86CrtcConfigPrivateIndex = xf86AllocateScrnInfoPrivateIndex(); + config = xnfcalloc (1, sizeof (xf86CrtcConfigRec)); + + config->funcs = funcs; + + scrn->privates[xf86CrtcConfigPrivateIndex].ptr = config; +} + +void +xf86CrtcSetSizeRange (ScrnInfoPtr scrn, + int minWidth, int minHeight, + int maxWidth, int maxHeight) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + + config->minWidth = minWidth; + config->minHeight = minHeight; + config->maxWidth = maxWidth; + config->maxHeight = maxHeight; +} + +/* + * Crtc functions + */ +xf86CrtcPtr +xf86CrtcCreate (ScrnInfoPtr scrn, + const xf86CrtcFuncsRec *funcs) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CrtcPtr crtc, *crtcs; + + crtc = xcalloc (sizeof (xf86CrtcRec), 1); + if (!crtc) + return NULL; + crtc->scrn = scrn; + crtc->funcs = funcs; +#ifdef RANDR_12_INTERFACE + crtc->randr_crtc = NULL; +#endif + crtc->rotation = RR_Rotate_0; + crtc->desiredRotation = RR_Rotate_0; + if (xf86_config->crtc) + crtcs = xrealloc (xf86_config->crtc, + (xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr)); + else + crtcs = xalloc ((xf86_config->num_crtc + 1) * sizeof (xf86CrtcPtr)); + if (!crtcs) + { + xfree (crtc); + return NULL; + } + xf86_config->crtc = crtcs; + xf86_config->crtc[xf86_config->num_crtc++] = crtc; + return crtc; +} + +void +xf86CrtcDestroy (xf86CrtcPtr crtc) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn); + int c; + + (*crtc->funcs->destroy) (crtc); + for (c = 0; c < xf86_config->num_crtc; c++) + if (xf86_config->crtc[c] == crtc) + { + memmove (&xf86_config->crtc[c], + &xf86_config->crtc[c+1], + xf86_config->num_crtc - (c + 1)); + xf86_config->num_crtc--; + break; + } + xfree (crtc); +} + + +/** + * Return whether any outputs are connected to the specified pipe + */ + +Bool +xf86CrtcInUse (xf86CrtcPtr crtc) +{ + ScrnInfoPtr pScrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int o; + + for (o = 0; o < xf86_config->num_output; o++) + if (xf86_config->output[o]->crtc == crtc) + return TRUE; + return FALSE; +} + +void +xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen) +{ +#ifdef RENDER + int subpixel_order = SubPixelUnknown; + Bool has_none = FALSE; + ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c, o; + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + for (o = 0; o < xf86_config->num_output; o++) + { + xf86OutputPtr output = xf86_config->output[o]; + + if (output->crtc == crtc) + { + switch (output->subpixel_order) { + case SubPixelNone: + has_none = TRUE; + break; + case SubPixelUnknown: + break; + default: + subpixel_order = output->subpixel_order; + break; + } + } + if (subpixel_order != SubPixelUnknown) + break; + } + if (subpixel_order != SubPixelUnknown) + { + static const int circle[4] = { + SubPixelHorizontalRGB, + SubPixelVerticalRGB, + SubPixelHorizontalBGR, + SubPixelVerticalBGR, + }; + int rotate; + int c; + for (rotate = 0; rotate < 4; rotate++) + if (crtc->rotation & (1 << rotate)) + break; + for (c = 0; c < 4; c++) + if (circle[c] == subpixel_order) + break; + c = (c + rotate) & 0x3; + if ((crtc->rotation & RR_Reflect_X) && !(c & 1)) + c ^= 2; + if ((crtc->rotation & RR_Reflect_Y) && (c & 1)) + c ^= 2; + subpixel_order = circle[c]; + break; + } + } + if (subpixel_order == SubPixelUnknown && has_none) + subpixel_order = SubPixelNone; + PictureSetSubpixelOrder (pScreen, subpixel_order); +#endif +} + +/** + * Sets the given video mode on the given crtc + */ +Bool +xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, + int x, int y) +{ + ScrnInfoPtr scrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int i; + Bool ret = FALSE; + Bool didLock = FALSE; + DisplayModePtr adjusted_mode; + DisplayModeRec saved_mode; + int saved_x, saved_y; + Rotation saved_rotation; + + adjusted_mode = xf86DuplicateMode(mode); + + crtc->enabled = xf86CrtcInUse (crtc); + + if (!crtc->enabled) + { + /* XXX disable crtc? */ + return TRUE; + } + + didLock = crtc->funcs->lock (crtc); + + saved_mode = crtc->mode; + saved_x = crtc->x; + saved_y = crtc->y; + saved_rotation = crtc->rotation; + /* Update crtc values up front so the driver can rely on them for mode + * setting. + */ + crtc->mode = *mode; + crtc->x = x; + crtc->y = y; + crtc->rotation = rotation; + + /* XXX short-circuit changes to base location only */ + + /* Pass our mode to the outputs and the CRTC to give them a chance to + * adjust it according to limitations or output properties, and also + * a chance to reject the mode entirely. + */ + for (i = 0; i < xf86_config->num_output; i++) { + xf86OutputPtr output = xf86_config->output[i]; + + if (output->crtc != crtc) + continue; + + if (!output->funcs->mode_fixup(output, mode, adjusted_mode)) { + goto done; + } + } + + if (!crtc->funcs->mode_fixup(crtc, mode, adjusted_mode)) { + goto done; + } + + if (!xf86CrtcRotate (crtc, mode, rotation)) { + goto done; + } + + /* Prepare the outputs and CRTCs before setting the mode. */ + for (i = 0; i < xf86_config->num_output; i++) { + xf86OutputPtr output = xf86_config->output[i]; + + if (output->crtc != crtc) + continue; + + /* Disable the output as the first thing we do. */ + output->funcs->prepare(output); + } + + crtc->funcs->prepare(crtc); + + /* Set up the DPLL and any output state that needs to adjust or depend + * on the DPLL. + */ + crtc->funcs->mode_set(crtc, mode, adjusted_mode, x, y); + for (i = 0; i < xf86_config->num_output; i++) + { + xf86OutputPtr output = xf86_config->output[i]; + if (output->crtc == crtc) + output->funcs->mode_set(output, mode, adjusted_mode); + } + + /* Now, enable the clocks, plane, pipe, and outputs that we set up. */ + crtc->funcs->commit(crtc); + for (i = 0; i < xf86_config->num_output; i++) + { + xf86OutputPtr output = xf86_config->output[i]; + if (output->crtc == crtc) + { + output->funcs->commit(output); +#ifdef RANDR_12_INTERFACE + if (output->randr_output) + RRPostPendingProperties (output->randr_output); +#endif + } + } + + /* XXX free adjustedmode */ + ret = TRUE; + if (scrn->pScreen) + xf86CrtcSetScreenSubpixelOrder (scrn->pScreen); + +done: + if (!ret) { + crtc->x = saved_x; + crtc->y = saved_y; + crtc->rotation = saved_rotation; + crtc->mode = saved_mode; + } + + if (didLock) + crtc->funcs->unlock (crtc); + + return ret; +} + +/* + * Output functions + */ + +extern XF86ConfigPtr xf86configptr; + +typedef enum { + OPTION_PREFERRED_MODE, + OPTION_POSITION, + OPTION_BELOW, + OPTION_RIGHT_OF, + OPTION_ABOVE, + OPTION_LEFT_OF, + OPTION_ENABLE, + OPTION_DISABLE, + OPTION_MIN_CLOCK, + OPTION_MAX_CLOCK, + OPTION_IGNORE, + OPTION_ROTATE, +} OutputOpts; + +static OptionInfoRec xf86OutputOptions[] = { + {OPTION_PREFERRED_MODE, "PreferredMode", OPTV_STRING, {0}, FALSE }, + {OPTION_POSITION, "Position", OPTV_STRING, {0}, FALSE }, + {OPTION_BELOW, "Below", OPTV_STRING, {0}, FALSE }, + {OPTION_RIGHT_OF, "RightOf", OPTV_STRING, {0}, FALSE }, + {OPTION_ABOVE, "Above", OPTV_STRING, {0}, FALSE }, + {OPTION_LEFT_OF, "LeftOf", OPTV_STRING, {0}, FALSE }, + {OPTION_ENABLE, "Enable", OPTV_BOOLEAN, {0}, FALSE }, + {OPTION_DISABLE, "Disable", OPTV_BOOLEAN, {0}, FALSE }, + {OPTION_MIN_CLOCK, "MinClock", OPTV_FREQ, {0}, FALSE }, + {OPTION_MAX_CLOCK, "MaxClock", OPTV_FREQ, {0}, FALSE }, + {OPTION_IGNORE, "Ignore", OPTV_BOOLEAN, {0}, FALSE }, + {OPTION_ROTATE, "Rotate", OPTV_STRING, {0}, FALSE }, + {-1, NULL, OPTV_NONE, {0}, FALSE }, +}; + +static void +xf86OutputSetMonitor (xf86OutputPtr output) +{ + char *option_name; + static const char monitor_prefix[] = "monitor-"; + char *monitor; + + if (!output->name) + return; + + if (output->options) + xfree (output->options); + + output->options = xnfalloc (sizeof (xf86OutputOptions)); + memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions)); + + option_name = xnfalloc (strlen (monitor_prefix) + + strlen (output->name) + 1); + strcpy (option_name, monitor_prefix); + strcat (option_name, output->name); + monitor = xf86findOptionValue (output->scrn->options, option_name); + if (!monitor) + monitor = output->name; + else + xf86MarkOptionUsedByName (output->scrn->options, option_name); + xfree (option_name); + output->conf_monitor = xf86findMonitor (monitor, + xf86configptr->conf_monitor_lst); + if (output->conf_monitor) + xf86ProcessOptions (output->scrn->scrnIndex, + output->conf_monitor->mon_option_lst, + output->options); +} + +static Bool +xf86OutputEnabled (xf86OutputPtr output) +{ + /* Check to see if this output was disabled in the config file */ + if (xf86ReturnOptValBool (output->options, OPTION_ENABLE, TRUE) == FALSE || + xf86ReturnOptValBool (output->options, OPTION_DISABLE, FALSE) == TRUE) + { + return FALSE; + } + return TRUE; +} + +static Bool +xf86OutputIgnored (xf86OutputPtr output) +{ + return xf86ReturnOptValBool (output->options, OPTION_IGNORE, FALSE); +} + +static char *direction[4] = { + "normal", + "left", + "inverted", + "right" +}; + +static Rotation +xf86OutputInitialRotation (xf86OutputPtr output) +{ + char *rotate_name = xf86GetOptValString (output->options, + OPTION_ROTATE); + int i; + + if (!rotate_name) + return RR_Rotate_0; + + for (i = 0; i < 4; i++) + if (xf86nameCompare (direction[i], rotate_name) == 0) + return (1 << i); + return RR_Rotate_0; +} + +xf86OutputPtr +xf86OutputCreate (ScrnInfoPtr scrn, + const xf86OutputFuncsRec *funcs, + const char *name) +{ + xf86OutputPtr output, *outputs; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int len; + + if (name) + len = strlen (name) + 1; + else + len = 0; + + output = xcalloc (sizeof (xf86OutputRec) + len, 1); + if (!output) + return NULL; + output->scrn = scrn; + output->funcs = funcs; + if (name) + { + output->name = (char *) (output + 1); + strcpy (output->name, name); + } + output->subpixel_order = SubPixelUnknown; +#ifdef RANDR_12_INTERFACE + output->randr_output = NULL; +#endif + if (name) + { + xf86OutputSetMonitor (output); + if (xf86OutputIgnored (output)) + { + xfree (output); + return FALSE; + } + } + + + if (xf86_config->output) + outputs = xrealloc (xf86_config->output, + (xf86_config->num_output + 1) * sizeof (xf86OutputPtr)); + else + outputs = xalloc ((xf86_config->num_output + 1) * sizeof (xf86OutputPtr)); + if (!outputs) + { + xfree (output); + return NULL; + } + + xf86_config->output = outputs; + xf86_config->output[xf86_config->num_output++] = output; + + return output; +} + +Bool +xf86OutputRename (xf86OutputPtr output, const char *name) +{ + int len = strlen(name) + 1; + char *newname = xalloc (len); + + if (!newname) + return FALSE; /* so sorry... */ + + strcpy (newname, name); + if (output->name && output->name != (char *) (output + 1)) + xfree (output->name); + output->name = newname; + xf86OutputSetMonitor (output); + if (xf86OutputIgnored (output)) + return FALSE; + return TRUE; +} + +void +xf86OutputDestroy (xf86OutputPtr output) +{ + ScrnInfoPtr scrn = output->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int o; + + (*output->funcs->destroy) (output); + while (output->probed_modes) + xf86DeleteMode (&output->probed_modes, output->probed_modes); + for (o = 0; o < xf86_config->num_output; o++) + if (xf86_config->output[o] == output) + { + memmove (&xf86_config->output[o], + &xf86_config->output[o+1], + xf86_config->num_output - (o + 1)); + xf86_config->num_output--; + break; + } + if (output->name && output->name != (char *) (output + 1)) + xfree (output->name); + xfree (output); +} + +/* + * Called during CreateScreenResources to hook up RandR + */ +static Bool +xf86CrtcCreateScreenResources (ScreenPtr screen) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + + screen->CreateScreenResources = config->CreateScreenResources; + + if (!(*screen->CreateScreenResources)(screen)) + return FALSE; + + if (!xf86RandR12CreateScreenResources (screen)) + return FALSE; + + return TRUE; +} + +/* + * Clean up config on server reset + */ +static Bool +xf86CrtcCloseScreen (int index, ScreenPtr screen) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int o, c; + + screen->CloseScreen = config->CloseScreen; + + xf86RotateCloseScreen (screen); + + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + output->crtc = NULL; + output->randr_output = NULL; + } + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + + crtc->randr_crtc = NULL; + } + return screen->CloseScreen (index, screen); +} + +/* + * Called at ScreenInit time to set up + */ +Bool +xf86CrtcScreenInit (ScreenPtr screen) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + /* Rotation */ + xf86DrvMsg(scrn->scrnIndex, X_INFO, "RandR 1.2 enabled, ignore the following RandR disabled message.\n"); + xf86DisableRandR(); /* Disable old RandR extension support */ + xf86RandR12Init (screen); + + /* support all rotations if every crtc has the shadow alloc funcs */ + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + if (!crtc->funcs->shadow_allocate || !crtc->funcs->shadow_create) + break; + } + if (c == config->num_crtc) + xf86RandR12SetRotations (screen, RR_Rotate_0 | RR_Rotate_90 | + RR_Rotate_180 | RR_Rotate_270); + else + xf86RandR12SetRotations (screen, RR_Rotate_0); + + /* Wrap CreateScreenResources so we can initialize the RandR code */ + config->CreateScreenResources = screen->CreateScreenResources; + screen->CreateScreenResources = xf86CrtcCreateScreenResources; + + config->CloseScreen = screen->CloseScreen; + screen->CloseScreen = xf86CrtcCloseScreen; + + return TRUE; +} + +static DisplayModePtr +xf86DefaultMode (xf86OutputPtr output, int width, int height) +{ + DisplayModePtr target_mode = NULL; + DisplayModePtr mode; + int target_diff = 0; + int target_preferred = 0; + int mm_height; + + mm_height = output->mm_height; + if (!mm_height) + mm_height = 203; /* 768 pixels at 96dpi */ + /* + * Pick a mode closest to 96dpi + */ + for (mode = output->probed_modes; mode; mode = mode->next) + { + int dpi; + int preferred = (mode->type & M_T_PREFERRED) != 0; + int diff; + + if (xf86ModeWidth (mode, output->initial_rotation) > width || + xf86ModeHeight (mode, output->initial_rotation) > height) + continue; + + /* yes, use VDisplay here, not xf86ModeHeight */ + dpi = (mode->VDisplay * 254) / (mm_height * 10); + diff = dpi - 96; + diff = diff < 0 ? -diff : diff; + if (target_mode == NULL || (preferred > target_preferred) || + (preferred == target_preferred && diff < target_diff)) + { + target_mode = mode; + target_diff = diff; + target_preferred = preferred; + } + } + return target_mode; +} + +static DisplayModePtr +xf86ClosestMode (xf86OutputPtr output, + DisplayModePtr match, Rotation match_rotation, + int width, int height) +{ + DisplayModePtr target_mode = NULL; + DisplayModePtr mode; + int target_diff = 0; + + /* + * Pick a mode closest to the specified mode + */ + for (mode = output->probed_modes; mode; mode = mode->next) + { + int dx, dy; + int diff; + + if (xf86ModeWidth (mode, output->initial_rotation) > width || + xf86ModeHeight (mode, output->initial_rotation) > height) + continue; + + /* exact matches are preferred */ + if (output->initial_rotation == match_rotation && + xf86ModesEqual (mode, match)) + return mode; + + dx = xf86ModeWidth (match, match_rotation) - xf86ModeWidth (mode, output->initial_rotation); + dy = xf86ModeHeight (match, match_rotation) - xf86ModeHeight (mode, output->initial_rotation); + diff = dx * dx + dy * dy; + if (target_mode == NULL || diff < target_diff) + { + target_mode = mode; + target_diff = diff; + } + } + return target_mode; +} + +static Bool +xf86OutputHasPreferredMode (xf86OutputPtr output, int width, int height) +{ + DisplayModePtr mode; + + for (mode = output->probed_modes; mode; mode = mode->next) + { + if (xf86ModeWidth (mode, output->initial_rotation) > width || + xf86ModeHeight (mode, output->initial_rotation) > height) + continue; + + if (mode->type & M_T_PREFERRED) + return TRUE; + } + return FALSE; +} + +static int +xf86PickCrtcs (ScrnInfoPtr scrn, + xf86CrtcPtr *best_crtcs, + DisplayModePtr *modes, + int n, + int width, + int height) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int c, o; + xf86OutputPtr output; + xf86CrtcPtr crtc; + xf86CrtcPtr *crtcs; + xf86CrtcPtr best_crtc; + int best_score; + int score; + int my_score; + + if (n == config->num_output) + return 0; + output = config->output[n]; + + /* + * Compute score with this output disabled + */ + best_crtcs[n] = NULL; + best_crtc = NULL; + best_score = xf86PickCrtcs (scrn, best_crtcs, modes, n+1, width, height); + if (modes[n] == NULL) + return best_score; + + crtcs = xalloc (config->num_output * sizeof (xf86CrtcPtr)); + if (!crtcs) + return best_score; + + my_score = 1; + /* Score outputs that are known to be connected higher */ + if (output->status == XF86OutputStatusConnected) + my_score++; + /* Score outputs with preferred modes higher */ + if (xf86OutputHasPreferredMode (output, width, height)) + my_score++; + /* + * Select a crtc for this output and + * then attempt to configure the remaining + * outputs + */ + for (c = 0; c < config->num_crtc; c++) + { + if ((output->possible_crtcs & (1 << c)) == 0) + continue; + + crtc = config->crtc[c]; + /* + * Check to see if some other output is + * using this crtc + */ + for (o = 0; o < n; o++) + if (best_crtcs[o] == crtc) + break; + if (o < n) + { + /* + * If the two outputs desire the same mode, + * see if they can be cloned + */ + if (xf86ModesEqual (modes[o], modes[n]) && + config->output[0]->initial_rotation == config->output[n]->initial_rotation && + config->output[o]->initial_x == config->output[n]->initial_x && + config->output[o]->initial_y == config->output[n]->initial_y) + { + if ((output->possible_clones & (1 << o)) == 0) + continue; /* nope, try next CRTC */ + } + else + continue; /* different modes, can't clone */ + } + crtcs[n] = crtc; + memcpy (crtcs, best_crtcs, n * sizeof (xf86CrtcPtr)); + score = my_score + xf86PickCrtcs (scrn, crtcs, modes, n+1, width, height); + if (score > best_score) + { + best_crtc = crtc; + best_score = score; + memcpy (best_crtcs, crtcs, config->num_output * sizeof (xf86CrtcPtr)); + } + } + xfree (crtcs); + return best_score; +} + + +/* + * Compute the virtual size necessary to place all of the available + * crtcs in the specified configuration. + * + * canGrow indicates that the driver can make the screen larger than its initial + * configuration. If FALSE, this function will enlarge the screen to include + * the largest available mode. + */ + +static void +xf86DefaultScreenLimits (ScrnInfoPtr scrn, int *widthp, int *heightp, + Bool canGrow) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int width = 0, height = 0; + int o; + int c; + int s; + + for (c = 0; c < config->num_crtc; c++) + { + int crtc_width = 0, crtc_height = 0; + xf86CrtcPtr crtc = config->crtc[c]; + + if (crtc->enabled) + { + crtc_width = crtc->x + xf86ModeWidth (&crtc->desiredMode, crtc->desiredRotation); + crtc_height = crtc->y + xf86ModeHeight (&crtc->desiredMode, crtc->desiredRotation); + } + if (!canGrow) { + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + for (s = 0; s < config->num_crtc; s++) + if (output->possible_crtcs & (1 << s)) + { + DisplayModePtr mode; + for (mode = output->probed_modes; mode; mode = mode->next) + { + if (mode->HDisplay > crtc_width) + crtc_width = mode->HDisplay; + if (mode->VDisplay > crtc_width) + crtc_width = mode->VDisplay; + if (mode->VDisplay > crtc_height) + crtc_height = mode->VDisplay; + if (mode->HDisplay > crtc_height) + crtc_height = mode->HDisplay; + } + } + } + } + if (crtc_width > width) + width = crtc_width; + if (crtc_height > height) + height = crtc_height; + } + if (config->maxWidth && width > config->maxWidth) width = config->maxWidth; + if (config->maxHeight && height > config->maxHeight) height = config->maxHeight; + if (config->minWidth && width < config->minWidth) width = config->minWidth; + if (config->minHeight && height < config->minHeight) height = config->minHeight; + *widthp = width; + *heightp = height; +} + +#define POSITION_UNSET -100000 + +static Bool +xf86InitialOutputPositions (ScrnInfoPtr scrn, DisplayModePtr *modes) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int o; + int min_x, min_y; + + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + output->initial_x = output->initial_y = POSITION_UNSET; + } + + /* + * Loop until all outputs are set + */ + for (;;) + { + Bool any_set = FALSE; + Bool keep_going = FALSE; + + for (o = 0; o < config->num_output; o++) + { + static const OutputOpts relations[] = { + OPTION_BELOW, OPTION_RIGHT_OF, OPTION_ABOVE, OPTION_LEFT_OF + }; + xf86OutputPtr output = config->output[o]; + xf86OutputPtr relative; + char *relative_name; + char *position; + OutputOpts relation; + int r; + + if (output->initial_x != POSITION_UNSET) + continue; + position = xf86GetOptValString (output->options, + OPTION_POSITION); + /* + * Absolute position wins + */ + if (position) + { + int x, y; + if (sscanf (position, "%d %d", &x, &y) == 2) + { + output->initial_x = x; + output->initial_y = y; + } + else + { + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Output %s position not of form \"x y\"\n", + output->name); + output->initial_x = output->initial_y = 0; + } + any_set = TRUE; + continue; + } + /* + * Next comes relative positions + */ + relation = 0; + relative_name = NULL; + for (r = 0; r < 4; r++) + { + relation = relations[r]; + relative_name = xf86GetOptValString (output->options, + relation); + if (relative_name) + break; + } + if (relative_name) + { + int or; + relative = NULL; + for (or = 0; or < config->num_output; or++) + { + xf86OutputPtr out_rel = config->output[or]; + XF86ConfMonitorPtr rel_mon = out_rel->conf_monitor; + + if (rel_mon) + { + if (xf86nameCompare (rel_mon->mon_identifier, + relative_name) == 0) + { + relative = config->output[or]; + break; + } + } + if (strcmp (out_rel->name, relative_name) == 0) + { + relative = config->output[or]; + break; + } + } + if (!relative) + { + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Cannot position output %s relative to unknown output %s\n", + output->name, relative_name); + output->initial_x = 0; + output->initial_y = 0; + any_set = TRUE; + continue; + } + if (relative->initial_x == POSITION_UNSET) + { + keep_going = TRUE; + continue; + } + output->initial_x = relative->initial_x; + output->initial_y = relative->initial_y; + switch (relation) { + case OPTION_BELOW: + output->initial_y += xf86ModeHeight (modes[or], relative->initial_rotation); + break; + case OPTION_RIGHT_OF: + output->initial_x += xf86ModeWidth (modes[or], relative->initial_rotation); + break; + case OPTION_ABOVE: + output->initial_y -= xf86ModeHeight (modes[or], relative->initial_rotation); + break; + case OPTION_LEFT_OF: + output->initial_x -= xf86ModeWidth (modes[or], relative->initial_rotation); + break; + default: + break; + } + any_set = TRUE; + continue; + } + + /* Nothing set, just stick them at 0,0 */ + output->initial_x = 0; + output->initial_y = 0; + any_set = TRUE; + } + if (!keep_going) + break; + if (!any_set) + { + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + if (output->initial_x == POSITION_UNSET) + { + xf86DrvMsg (scrn->scrnIndex, X_ERROR, + "Output position loop. Moving %s to 0,0\n", + output->name); + output->initial_x = output->initial_y = 0; + break; + } + } + } + } + + /* + * normalize positions + */ + min_x = 1000000; + min_y = 1000000; + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + if (output->initial_x < min_x) + min_x = output->initial_x; + if (output->initial_y < min_y) + min_y = output->initial_y; + } + + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + output->initial_x -= min_x; + output->initial_y -= min_y; + } + return TRUE; +} + +/* + * XXX walk the monitor mode list and prune out duplicates that + * are inserted by xf86DDCMonitorSet. In an ideal world, that + * function would do this work by itself. + */ + +static void +xf86PruneDuplicateMonitorModes (MonPtr Monitor) +{ + DisplayModePtr master, clone, next; + + for (master = Monitor->Modes; + master && master != Monitor->Last; + master = master->next) + { + for (clone = master->next; clone && clone != Monitor->Modes; clone = next) + { + next = clone->next; + if (xf86ModesEqual (master, clone)) + { + if (Monitor->Last == clone) + Monitor->Last = clone->prev; + xf86DeleteMode (&Monitor->Modes, clone); + } + } + } +} + +/** Return - 0 + if a should be earlier, same or later than b in list + */ +static int +xf86ModeCompare (DisplayModePtr a, DisplayModePtr b) +{ + int diff; + + diff = ((b->type & M_T_PREFERRED) != 0) - ((a->type & M_T_PREFERRED) != 0); + if (diff) + return diff; + diff = b->HDisplay * b->VDisplay - a->HDisplay * a->VDisplay; + if (diff) + return diff; + diff = b->Clock - a->Clock; + return diff; +} + +/** + * Insertion sort input in-place and return the resulting head + */ +static DisplayModePtr +xf86SortModes (DisplayModePtr input) +{ + DisplayModePtr output = NULL, i, o, n, *op, prev; + + /* sort by preferred status and pixel area */ + while (input) + { + i = input; + input = input->next; + for (op = &output; (o = *op); op = &o->next) + if (xf86ModeCompare (o, i) > 0) + break; + i->next = *op; + *op = i; + } + /* prune identical modes */ + for (o = output; o && (n = o->next); o = n) + { + if (!strcmp (o->name, n->name) && xf86ModesEqual (o, n)) + { + o->next = n->next; + xfree (n->name); + xfree (n); + n = o; + } + } + /* hook up backward links */ + prev = NULL; + for (o = output; o; o = o->next) + { + o->prev = prev; + prev = o; + } + return output; +} + +#define DEBUG_REPROBE 1 + +void +xf86ProbeOutputModes (ScrnInfoPtr scrn, int maxX, int maxY) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int o; + + if (maxX == 0 || maxY == 0) + xf86RandR12GetOriginalVirtualSize (scrn, &maxX, &maxY); + + /* Elide duplicate modes before defaulting code uses them */ + xf86PruneDuplicateMonitorModes (scrn->monitor); + + /* Probe the list of modes for each output. */ + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + DisplayModePtr mode; + DisplayModePtr config_modes = NULL, output_modes, default_modes; + char *preferred_mode; + xf86MonPtr edid_monitor; + XF86ConfMonitorPtr conf_monitor; + MonRec mon_rec; + int min_clock = 0; + int max_clock = 0; + double clock; + enum { sync_config, sync_edid, sync_default } sync_source = sync_default; + + while (output->probed_modes != NULL) + xf86DeleteMode(&output->probed_modes, output->probed_modes); + + /* + * Check connection status + */ + output->status = (*output->funcs->detect)(output); + + if (output->status == XF86OutputStatusDisconnected) + { + xf86OutputSetEDID (output, NULL); + continue; + } + + memset (&mon_rec, '\0', sizeof (mon_rec)); + + conf_monitor = output->conf_monitor; + + if (conf_monitor) + { + int i; + + for (i = 0; i < conf_monitor->mon_n_hsync; i++) + { + mon_rec.hsync[mon_rec.nHsync].lo = conf_monitor->mon_hsync[i].lo; + mon_rec.hsync[mon_rec.nHsync].hi = conf_monitor->mon_hsync[i].hi; + mon_rec.nHsync++; + sync_source = sync_config; + } + for (i = 0; i < conf_monitor->mon_n_vrefresh; i++) + { + mon_rec.vrefresh[mon_rec.nVrefresh].lo = conf_monitor->mon_vrefresh[i].lo; + mon_rec.vrefresh[mon_rec.nVrefresh].hi = conf_monitor->mon_vrefresh[i].hi; + mon_rec.nVrefresh++; + sync_source = sync_config; + } + config_modes = xf86GetMonitorModes (scrn, conf_monitor); + } + + output_modes = (*output->funcs->get_modes) (output); + + edid_monitor = output->MonInfo; + + if (edid_monitor) + { + int i; + Bool set_hsync = mon_rec.nHsync == 0; + Bool set_vrefresh = mon_rec.nVrefresh == 0; + + for (i = 0; i < sizeof (edid_monitor->det_mon) / sizeof (edid_monitor->det_mon[0]); i++) + { + if (edid_monitor->det_mon[i].type == DS_RANGES) + { + struct monitor_ranges *ranges = &edid_monitor->det_mon[i].section.ranges; + if (set_hsync && ranges->max_h) + { + mon_rec.hsync[mon_rec.nHsync].lo = ranges->min_h; + mon_rec.hsync[mon_rec.nHsync].hi = ranges->max_h; + mon_rec.nHsync++; + if (sync_source == sync_default) + sync_source = sync_edid; + } + if (set_vrefresh && ranges->max_v) + { + mon_rec.vrefresh[mon_rec.nVrefresh].lo = ranges->min_v; + mon_rec.vrefresh[mon_rec.nVrefresh].hi = ranges->max_v; + mon_rec.nVrefresh++; + if (sync_source == sync_default) + sync_source = sync_edid; + } + if (ranges->max_clock > max_clock) + max_clock = ranges->max_clock; + } + } + } + + if (xf86GetOptValFreq (output->options, OPTION_MIN_CLOCK, + OPTUNITS_KHZ, &clock)) + min_clock = (int) clock; + if (xf86GetOptValFreq (output->options, OPTION_MAX_CLOCK, + OPTUNITS_KHZ, &clock)) + max_clock = (int) clock; + + /* + * These limits will end up setting a 1024x768@60Hz mode by default, + * which seems like a fairly good mode to use when nothing else is + * specified + */ + if (mon_rec.nHsync == 0) + { + mon_rec.hsync[0].lo = 31.0; + mon_rec.hsync[0].hi = 55.0; + mon_rec.nHsync = 1; + } + if (mon_rec.nVrefresh == 0) + { + mon_rec.vrefresh[0].lo = 58.0; + mon_rec.vrefresh[0].hi = 62.0; + mon_rec.nVrefresh = 1; + } + default_modes = xf86GetDefaultModes (output->interlaceAllowed, + output->doubleScanAllowed); + + if (sync_source == sync_config) + { + /* + * Check output and config modes against sync range from config file + */ + xf86ValidateModesSync (scrn, output_modes, &mon_rec); + xf86ValidateModesSync (scrn, config_modes, &mon_rec); + } + /* + * Check default modes against sync range + */ + xf86ValidateModesSync (scrn, default_modes, &mon_rec); + /* + * Check default modes against monitor max clock + */ + if (max_clock) + xf86ValidateModesClocks(scrn, default_modes, + &min_clock, &max_clock, 1); + + output->probed_modes = NULL; + output->probed_modes = xf86ModesAdd (output->probed_modes, config_modes); + output->probed_modes = xf86ModesAdd (output->probed_modes, output_modes); + output->probed_modes = xf86ModesAdd (output->probed_modes, default_modes); + + /* + * Check all modes against max size + */ + if (maxX && maxY) + xf86ValidateModesSize (scrn, output->probed_modes, + maxX, maxY, 0); + + /* + * Check all modes against output + */ + for (mode = output->probed_modes; mode != NULL; mode = mode->next) + if (mode->status == MODE_OK) + mode->status = (*output->funcs->mode_valid)(output, mode); + + xf86PruneInvalidModes(scrn, &output->probed_modes, TRUE); + + output->probed_modes = xf86SortModes (output->probed_modes); + + /* Check for a configured preference for a particular mode */ + preferred_mode = xf86GetOptValString (output->options, + OPTION_PREFERRED_MODE); + + if (preferred_mode) + { + for (mode = output->probed_modes; mode; mode = mode->next) + { + if (!strcmp (preferred_mode, mode->name)) + { + if (mode != output->probed_modes) + { + if (mode->prev) + mode->prev->next = mode->next; + if (mode->next) + mode->next->prev = mode->prev; + mode->next = output->probed_modes; + output->probed_modes->prev = mode; + mode->prev = NULL; + output->probed_modes = mode; + } + mode->type |= M_T_PREFERRED; + break; + } + } + } + + output->initial_rotation = xf86OutputInitialRotation (output); + +#ifdef DEBUG_REPROBE + if (output->probed_modes != NULL) { + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "Printing probed modes for output %s\n", + output->name); + } else { + xf86DrvMsg(scrn->scrnIndex, X_INFO, + "No remaining probed modes for output %s\n", + output->name); + } +#endif + for (mode = output->probed_modes; mode != NULL; mode = mode->next) + { + /* The code to choose the best mode per pipe later on will require + * VRefresh to be set. + */ + mode->VRefresh = xf86ModeVRefresh(mode); + xf86SetModeCrtc(mode, INTERLACE_HALVE_V); + +#ifdef DEBUG_REPROBE + xf86PrintModeline(scrn->scrnIndex, mode); +#endif + } + } +} + + +/** + * Copy one of the output mode lists to the ScrnInfo record + */ + +/* XXX where does this function belong? Here? */ +void +xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr scrn, int *x, int *y); + +void +xf86SetScrnInfoModes (ScrnInfoPtr scrn) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + xf86OutputPtr output; + xf86CrtcPtr crtc; + DisplayModePtr last, mode; + + output = config->output[config->compat_output]; + if (!output->crtc) + { + int o; + + output = NULL; + for (o = 0; o < config->num_output; o++) + if (config->output[o]->crtc) + { + config->compat_output = o; + output = config->output[o]; + break; + } + /* no outputs are active, punt and leave things as they are */ + if (!output) + return; + } + crtc = output->crtc; + + /* Clear any existing modes from scrn->modes */ + while (scrn->modes != NULL) + xf86DeleteMode(&scrn->modes, scrn->modes); + + /* Set scrn->modes to the mode list for the 'compat' output */ + scrn->modes = xf86DuplicateModes(scrn, output->probed_modes); + + for (mode = scrn->modes; mode; mode = mode->next) + if (xf86ModesEqual (mode, &crtc->desiredMode)) + break; + + if (scrn->modes != NULL) { + /* For some reason, scrn->modes is circular, unlike the other mode + * lists. How great is that? + */ + for (last = scrn->modes; last && last->next; last = last->next) + ; + last->next = scrn->modes; + scrn->modes->prev = last; + if (mode) { + while (scrn->modes != mode) + scrn->modes = scrn->modes->next; + } + } + scrn->currentMode = scrn->modes; +} + +/** + * Construct default screen configuration + * + * Given auto-detected (and, eventually, configured) values, + * construct a usable configuration for the system + * + * canGrow indicates that the driver can resize the screen to larger than its + * initially configured size via the config->funcs->resize hook. If TRUE, this + * function will set virtualX and virtualY to match the initial configuration + * and leave config->max{Width,Height} alone. If FALSE, it will bloat + * virtual[XY] to include the largest modes and set config->max{Width,Height} + * accordingly. + */ + +Bool +xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int o, c; + DisplayModePtr target_mode = NULL; + Rotation target_rotation = RR_Rotate_0; + xf86CrtcPtr *crtcs; + DisplayModePtr *modes; + Bool *enabled; + int width; + int height; + + if (scrn->display->virtualX) + width = scrn->display->virtualX; + else + width = config->maxWidth; + if (scrn->display->virtualY) + height = scrn->display->virtualY; + else + height = config->maxHeight; + + xf86ProbeOutputModes (scrn, width, height); + + crtcs = xnfcalloc (config->num_output, sizeof (xf86CrtcPtr)); + modes = xnfcalloc (config->num_output, sizeof (DisplayModePtr)); + enabled = xnfcalloc (config->num_output, sizeof (Bool)); + + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + modes[o] = NULL; + enabled[o] = (xf86OutputEnabled (output) && + output->status != XF86OutputStatusDisconnected); + } + + /* + * Let outputs with preferred modes drive screen size + */ + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + if (enabled[o] && + xf86OutputHasPreferredMode (output, width, height)) + { + target_mode = xf86DefaultMode (output, width, height); + target_rotation = output->initial_rotation; + if (target_mode) + { + modes[o] = target_mode; + config->compat_output = o; + break; + } + } + } + if (!target_mode) + { + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + if (enabled[o]) + { + target_mode = xf86DefaultMode (output, width, height); + target_rotation = output->initial_rotation; + if (target_mode) + { + modes[o] = target_mode; + config->compat_output = o; + break; + } + } + } + } + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + if (enabled[o] && !modes[o]) + modes[o] = xf86ClosestMode (output, target_mode, target_rotation, width, height); + } + + /* + * Set the position of each output + */ + if (!xf86InitialOutputPositions (scrn, modes)) + { + xfree (crtcs); + xfree (modes); + return FALSE; + } + + /* + * Assign CRTCs to fit output configuration + */ + if (!xf86PickCrtcs (scrn, crtcs, modes, 0, width, height)) + { + xfree (crtcs); + xfree (modes); + return FALSE; + } + + /* XXX override xf86 common frame computation code */ + + scrn->display->frameX0 = 0; + scrn->display->frameY0 = 0; + + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + + crtc->enabled = FALSE; + memset (&crtc->desiredMode, '\0', sizeof (crtc->desiredMode)); + } + + /* + * Set initial configuration + */ + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + DisplayModePtr mode = modes[o]; + xf86CrtcPtr crtc = crtcs[o]; + + if (mode && crtc) + { + crtc->desiredMode = *mode; + crtc->desiredRotation = output->initial_rotation; + crtc->desiredX = output->initial_x; + crtc->desiredY = output->initial_y; + crtc->enabled = TRUE; + crtc->x = output->initial_x; + crtc->y = output->initial_y; + output->crtc = crtc; + } + } + + if (scrn->display->virtualX == 0) + { + /* + * Expand virtual size to cover the current config and potential mode + * switches, if the driver can't enlarge the screen later. + */ + xf86DefaultScreenLimits (scrn, &width, &height, canGrow); + + scrn->display->virtualX = width; + scrn->display->virtualY = height; + } + + if (width > scrn->virtualX) + scrn->virtualX = width; + if (height > scrn->virtualY) + scrn->virtualY = height; + + /* + * Make sure the configuration isn't too small. + */ + if (width < config->minWidth || height < config->minHeight) + return FALSE; + + /* + * Limit the crtc config to virtual[XY] if the driver can't grow the + * desktop. + */ + if (!canGrow) + { + xf86CrtcSetSizeRange (scrn, config->minWidth, config->minHeight, + width, height); + } + + /* Mirror output modes to scrn mode list */ + xf86SetScrnInfoModes (scrn); + + xfree (crtcs); + xfree (modes); + return TRUE; +} + +/* + * Using the desired mode information in each crtc, set + * modes (used in EnterVT functions, or at server startup) + */ + +Bool +xf86SetDesiredModes (ScrnInfoPtr scrn) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + xf86OutputPtr output = NULL; + int o; + + if (config->output[config->compat_output]->crtc == crtc) + output = config->output[config->compat_output]; + else + { + for (o = 0; o < config->num_output; o++) + if (config->output[o]->crtc == crtc) + { + output = config->output[o]; + break; + } + } + /* + * Skip disabled crtcs + */ + if (!output) + continue; + + /* Mark that we'll need to re-set the mode for sure */ + memset(&crtc->mode, 0, sizeof(crtc->mode)); + if (!crtc->desiredMode.CrtcHDisplay) + { + DisplayModePtr mode = xf86OutputFindClosestMode (output, scrn->currentMode); + + if (!mode) + return FALSE; + crtc->desiredMode = *mode; + crtc->desiredRotation = RR_Rotate_0; + crtc->desiredX = 0; + crtc->desiredY = 0; + } + + if (!xf86CrtcSetMode (crtc, &crtc->desiredMode, crtc->desiredRotation, + crtc->desiredX, crtc->desiredY)) + return FALSE; + } + + xf86DisableUnusedFunctions(scrn); + return TRUE; +} + +/** + * In the current world order, there are lists of modes per output, which may + * or may not include the mode that was asked to be set by XFree86's mode + * selection. Find the closest one, in the following preference order: + * + * - Equality + * - Closer in size to the requested mode, but no larger + * - Closer in refresh rate to the requested mode. + */ + +DisplayModePtr +xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired) +{ + DisplayModePtr best = NULL, scan = NULL; + + for (scan = output->probed_modes; scan != NULL; scan = scan->next) + { + /* If there's an exact match, we're done. */ + if (xf86ModesEqual(scan, desired)) { + best = desired; + break; + } + + /* Reject if it's larger than the desired mode. */ + if (scan->HDisplay > desired->HDisplay || + scan->VDisplay > desired->VDisplay) + { + continue; + } + + /* + * If we haven't picked a best mode yet, use the first + * one in the size range + */ + if (best == NULL) + { + best = scan; + continue; + } + + /* Find if it's closer to the right size than the current best + * option. + */ + if ((scan->HDisplay > best->HDisplay && + scan->VDisplay >= best->VDisplay) || + (scan->HDisplay >= best->HDisplay && + scan->VDisplay > best->VDisplay)) + { + best = scan; + continue; + } + + /* Find if it's still closer to the right refresh than the current + * best resolution. + */ + if (scan->HDisplay == best->HDisplay && + scan->VDisplay == best->VDisplay && + (fabs(scan->VRefresh - desired->VRefresh) < + fabs(best->VRefresh - desired->VRefresh))) { + best = scan; + } + } + return best; +} + +/** + * When setting a mode through XFree86-VidModeExtension or XFree86-DGA, + * take the specified mode and apply it to the crtc connected to the compat + * output. Then, find similar modes for the other outputs, as with the + * InitialConfiguration code above. The goal is to clone the desired + * mode across all outputs that are currently active. + */ + +Bool +xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + Bool ok = TRUE; + xf86OutputPtr compat_output = config->output[config->compat_output]; + DisplayModePtr compat_mode; + int c; + + /* + * Let the compat output drive the final mode selection + */ + compat_mode = xf86OutputFindClosestMode (compat_output, desired); + if (compat_mode) + desired = compat_mode; + + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + DisplayModePtr crtc_mode = NULL; + int o; + + if (!crtc->enabled) + continue; + + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + DisplayModePtr output_mode; + + /* skip outputs not on this crtc */ + if (output->crtc != crtc) + continue; + + if (crtc_mode) + { + output_mode = xf86OutputFindClosestMode (output, crtc_mode); + if (output_mode != crtc_mode) + output->crtc = NULL; + } + else + crtc_mode = xf86OutputFindClosestMode (output, desired); + } + if (!xf86CrtcSetMode (crtc, crtc_mode, rotation, 0, 0)) + ok = FALSE; + else + { + crtc->desiredMode = *crtc_mode; + crtc->desiredRotation = rotation; + crtc->desiredX = 0; + crtc->desiredY = 0; + } + } + xf86DisableUnusedFunctions(pScrn); + return ok; +} + + +/** + * Set the DPMS power mode of all outputs and CRTCs. + * + * If the new mode is off, it will turn off outputs and then CRTCs. + * Otherwise, it will affect CRTCs before outputs. + */ +void +xf86DPMSSet(ScrnInfoPtr scrn, int mode, int flags) +{ + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int i; + + if (!scrn->vtSema) + return; + + if (mode == DPMSModeOff) { + for (i = 0; i < config->num_output; i++) { + xf86OutputPtr output = config->output[i]; + if (output->crtc != NULL) + (*output->funcs->dpms) (output, mode); + } + } + + for (i = 0; i < config->num_crtc; i++) { + xf86CrtcPtr crtc = config->crtc[i]; + if (crtc->enabled) + (*crtc->funcs->dpms) (crtc, mode); + } + + if (mode != DPMSModeOff) { + for (i = 0; i < config->num_output; i++) { + xf86OutputPtr output = config->output[i]; + if (output->crtc != NULL) + (*output->funcs->dpms) (output, mode); + } + } +} + +/** + * Implement the screensaver by just calling down into the driver DPMS hooks. + * + * Even for monitors with no DPMS support, by the definition of our DPMS hooks, + * the outputs will still get disabled (blanked). + */ +Bool +xf86SaveScreen(ScreenPtr pScreen, int mode) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + if (xf86IsUnblank(mode)) + xf86DPMSSet(pScrn, DPMSModeOn, 0); + else + xf86DPMSSet(pScrn, DPMSModeOff, 0); + + return TRUE; +} + +/** + * Disable all inactive crtcs and outputs + */ +void +xf86DisableUnusedFunctions(ScrnInfoPtr pScrn) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int o, c; + + for (o = 0; o < xf86_config->num_output; o++) + { + xf86OutputPtr output = xf86_config->output[o]; + if (!output->crtc) + (*output->funcs->dpms)(output, DPMSModeOff); + } + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (!crtc->enabled) + { + crtc->funcs->dpms(crtc, DPMSModeOff); + memset(&crtc->mode, 0, sizeof(crtc->mode)); + } + } +} + +#ifdef RANDR_12_INTERFACE + +#define EDID_ATOM_NAME "EDID_DATA" + +/** + * Set the RandR EDID property + */ +static void +xf86OutputSetEDIDProperty (xf86OutputPtr output, void *data, int data_len) +{ + Atom edid_atom = MakeAtom(EDID_ATOM_NAME, sizeof(EDID_ATOM_NAME), TRUE); + + /* This may get called before the RandR resources have been created */ + if (output->randr_output == NULL) + return; + + if (data_len != 0) { + RRChangeOutputProperty(output->randr_output, edid_atom, XA_INTEGER, 8, + PropModeReplace, data_len, data, FALSE, TRUE); + } else { + RRDeleteOutputProperty(output->randr_output, edid_atom); + } +} + +#endif + +/** + * Set the EDID information for the specified output + */ +void +xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon) +{ + ScrnInfoPtr scrn = output->scrn; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(scrn); + int i; +#ifdef RANDR_12_INTERFACE + int size; +#endif + + if (output->MonInfo != NULL) + xfree(output->MonInfo); + + output->MonInfo = edid_mon; + + /* Debug info for now, at least */ + xf86DrvMsg(scrn->scrnIndex, X_INFO, "EDID for output %s\n", output->name); + xf86PrintEDID(edid_mon); + + /* Set the DDC properties for the 'compat' output */ + if (output == config->output[config->compat_output]) + xf86SetDDCproperties(scrn, edid_mon); + +#ifdef RANDR_12_INTERFACE + /* Set the RandR output properties */ + size = 0; + if (edid_mon) + { + if (edid_mon->ver.version == 1) + size = 128; + else if (edid_mon->ver.version == 2) + size = 256; + } + xf86OutputSetEDIDProperty (output, edid_mon ? edid_mon->rawData : NULL, size); +#endif + + if (edid_mon) + { + /* Pull out a phyiscal size from a detailed timing if available. */ + for (i = 0; i < 4; i++) { + if (edid_mon->det_mon[i].type == DT && + edid_mon->det_mon[i].section.d_timings.h_size != 0 && + edid_mon->det_mon[i].section.d_timings.v_size != 0) + { + output->mm_width = edid_mon->det_mon[i].section.d_timings.h_size; + output->mm_height = edid_mon->det_mon[i].section.d_timings.v_size; + break; + } + } + + /* if no mm size is available from a detailed timing, check the max size field */ + if ((!output->mm_width || !output->mm_height) && + (edid_mon->features.hsize && edid_mon->features.vsize)) + { + output->mm_width = edid_mon->features.hsize * 10; + output->mm_height = edid_mon->features.vsize * 10; + } + } +} + +/** + * Return the list of modes supported by the EDID information + * stored in 'output' + */ +DisplayModePtr +xf86OutputGetEDIDModes (xf86OutputPtr output) +{ + ScrnInfoPtr scrn = output->scrn; + xf86MonPtr edid_mon = output->MonInfo; + + if (!edid_mon) + return NULL; + return xf86DDCGetModes(scrn->scrnIndex, edid_mon); +} + +xf86MonPtr +xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus) +{ + ScrnInfoPtr scrn = output->scrn; + + return xf86DoEDID_DDC2 (scrn->scrnIndex, pDDCBus); +} + +static char *_xf86ConnectorNames[] = { "None", "VGA", "DVI-I", "DVI-D", + "DVI-A", "Composite", "S-Video", + "Component", "LFP", "Proprietary" }; +char * +xf86ConnectorGetName(xf86ConnectorType connector) +{ + return _xf86ConnectorNames[connector]; +} diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h new file mode 100644 index 000000000..42daf6079 --- /dev/null +++ b/hw/xfree86/modes/xf86Crtc.h @@ -0,0 +1,740 @@ +/* + * 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. + */ +#ifndef _XF86CRTC_H_ +#define _XF86CRTC_H_ + +#include <edid.h> +#include "randrstr.h" +#if XF86_MODES_RENAME +#include "xf86Rename.h" +#endif +#include "xf86Modes.h" +#include "xf86Cursor.h" +#include "damage.h" + +/* Compat definitions for older X Servers. */ +#ifndef M_T_PREFERRED +#define M_T_PREFERRED 0x08 +#endif +#ifndef M_T_DRIVER +#define M_T_DRIVER 0x40 +#endif +#ifndef HARDWARE_CURSOR_ARGB +#define HARDWARE_CURSOR_ARGB 0x00004000 +#endif + +typedef struct _xf86Crtc xf86CrtcRec, *xf86CrtcPtr; +typedef struct _xf86Output xf86OutputRec, *xf86OutputPtr; + +/* define a standard for connector types */ +typedef enum _xf86ConnectorType { + XF86ConnectorNone, + XF86ConnectorVGA, + XF86ConnectorDVI_I, + XF86ConnectorDVI_D, + XF86ConnectorDVI_A, + XF86ConnectorComposite, + XF86ConnectorSvideo, + XF86ConnectorComponent, + XF86ConnectorLFP, + XF86ConnectorProprietary, +} xf86ConnectorType; + +typedef enum _xf86OutputStatus { + XF86OutputStatusConnected, + XF86OutputStatusDisconnected, + XF86OutputStatusUnknown, +} xf86OutputStatus; + +typedef struct _xf86CrtcFuncs { + /** + * Turns the crtc on/off, or sets intermediate power levels if available. + * + * Unsupported intermediate modes drop to the lower power setting. If the + * mode is DPMSModeOff, the crtc must be disabled sufficiently for it to + * be safe to call mode_set. + */ + void + (*dpms)(xf86CrtcPtr crtc, + int mode); + + /** + * Saves the crtc's state for restoration on VT switch. + */ + void + (*save)(xf86CrtcPtr crtc); + + /** + * Restore's the crtc's state at VT switch. + */ + void + (*restore)(xf86CrtcPtr crtc); + + /** + * Lock CRTC prior to mode setting, mostly for DRI. + * Returns whether unlock is needed + */ + Bool + (*lock) (xf86CrtcPtr crtc); + + /** + * Unlock CRTC after mode setting, mostly for DRI + */ + void + (*unlock) (xf86CrtcPtr crtc); + + /** + * Callback to adjust the mode to be set in the CRTC. + * + * This allows a CRTC to adjust the clock or even the entire set of + * timings, which is used for panels with fixed timings or for + * buses with clock limitations. + */ + Bool + (*mode_fixup)(xf86CrtcPtr crtc, + DisplayModePtr mode, + DisplayModePtr adjusted_mode); + + /** + * Prepare CRTC for an upcoming mode set. + */ + void + (*prepare)(xf86CrtcPtr crtc); + + /** + * Callback for setting up a video mode after fixups have been made. + */ + void + (*mode_set)(xf86CrtcPtr crtc, + DisplayModePtr mode, + DisplayModePtr adjusted_mode, + int x, int y); + + /** + * Commit mode changes to a CRTC + */ + void + (*commit)(xf86CrtcPtr crtc); + + /* Set the color ramps for the CRTC to the given values. */ + void + (*gamma_set)(xf86CrtcPtr crtc, CARD16 *red, CARD16 *green, CARD16 *blue, + int size); + + /** + * Allocate the shadow area, delay the pixmap creation until needed + */ + void * + (*shadow_allocate) (xf86CrtcPtr crtc, int width, int height); + + /** + * Create shadow pixmap for rotation support + */ + PixmapPtr + (*shadow_create) (xf86CrtcPtr crtc, void *data, int width, int height); + + /** + * Destroy shadow pixmap + */ + void + (*shadow_destroy) (xf86CrtcPtr crtc, PixmapPtr pPixmap, void *data); + + /** + * Set cursor colors + */ + void + (*set_cursor_colors) (xf86CrtcPtr crtc, int bg, int fg); + + /** + * Set cursor position + */ + void + (*set_cursor_position) (xf86CrtcPtr crtc, int x, int y); + + /** + * Show cursor + */ + void + (*show_cursor) (xf86CrtcPtr crtc); + + /** + * Hide cursor + */ + void + (*hide_cursor) (xf86CrtcPtr crtc); + + /** + * Load monochrome image + */ + void + (*load_cursor_image) (xf86CrtcPtr crtc, CARD8 *image); + + /** + * Load ARGB image + */ + void + (*load_cursor_argb) (xf86CrtcPtr crtc, CARD32 *image); + + /** + * Clean up driver-specific bits of the crtc + */ + void + (*destroy) (xf86CrtcPtr crtc); +} xf86CrtcFuncsRec, *xf86CrtcFuncsPtr; + +struct _xf86Crtc { + /** + * Associated ScrnInfo + */ + ScrnInfoPtr scrn; + + /** + * Active state of this CRTC + * + * Set when this CRTC is driving one or more outputs + */ + Bool enabled; + + /** + * Active mode + * + * This reflects the mode as set in the CRTC currently + * It will be cleared when the VT is not active or + * during server startup + */ + DisplayModeRec mode; + Rotation rotation; + PixmapPtr rotatedPixmap; + void *rotatedData; + + /** + * Position on screen + * + * Locates this CRTC within the frame buffer + */ + int x, y; + + /** + * Desired mode + * + * This is set to the requested mode, independent of + * whether the VT is active. In particular, it receives + * the startup configured mode and saves the active mode + * on VT switch. + */ + DisplayModeRec desiredMode; + Rotation desiredRotation; + int desiredX, desiredY; + + /** crtc-specific functions */ + const xf86CrtcFuncsRec *funcs; + + /** + * Driver private + * + * Holds driver-private information + */ + void *driver_private; + +#ifdef RANDR_12_INTERFACE + /** + * RandR crtc + * + * When RandR 1.2 is available, this + * points at the associated crtc object + */ + RRCrtcPtr randr_crtc; +#else + void *randr_crtc; +#endif + + /** + * Current cursor is ARGB + */ + Bool cursor_argb; + /** + * Track whether cursor is within CRTC range + */ + Bool cursor_in_range; + /** + * Track state of cursor associated with this CRTC + */ + Bool cursor_shown; +}; + +typedef struct _xf86OutputFuncs { + /** + * Called to allow the output a chance to create properties after the + * RandR objects have been created. + */ + void + (*create_resources)(xf86OutputPtr output); + + /** + * Turns the output on/off, or sets intermediate power levels if available. + * + * Unsupported intermediate modes drop to the lower power setting. If the + * mode is DPMSModeOff, the output must be disabled, as the DPLL may be + * disabled afterwards. + */ + void + (*dpms)(xf86OutputPtr output, + int mode); + + /** + * Saves the output's state for restoration on VT switch. + */ + void + (*save)(xf86OutputPtr output); + + /** + * Restore's the output's state at VT switch. + */ + void + (*restore)(xf86OutputPtr output); + + /** + * Callback for testing a video mode for a given output. + * + * This function should only check for cases where a mode can't be supported + * on the output specifically, and not represent generic CRTC limitations. + * + * \return MODE_OK if the mode is valid, or another MODE_* otherwise. + */ + int + (*mode_valid)(xf86OutputPtr output, + DisplayModePtr pMode); + + /** + * Callback to adjust the mode to be set in the CRTC. + * + * This allows an output to adjust the clock or even the entire set of + * timings, which is used for panels with fixed timings or for + * buses with clock limitations. + */ + Bool + (*mode_fixup)(xf86OutputPtr output, + DisplayModePtr mode, + DisplayModePtr adjusted_mode); + + /** + * Callback for preparing mode changes on an output + */ + void + (*prepare)(xf86OutputPtr output); + + /** + * Callback for committing mode changes on an output + */ + void + (*commit)(xf86OutputPtr output); + + /** + * Callback for setting up a video mode after fixups have been made. + * + * This is only called while the output is disabled. The dpms callback + * must be all that's necessary for the output, to turn the output on + * after this function is called. + */ + void + (*mode_set)(xf86OutputPtr output, + DisplayModePtr mode, + DisplayModePtr adjusted_mode); + + /** + * Probe for a connected output, and return detect_status. + */ + xf86OutputStatus + (*detect)(xf86OutputPtr output); + + /** + * Query the device for the modes it provides. + * + * This function may also update MonInfo, mm_width, and mm_height. + * + * \return singly-linked list of modes or NULL if no modes found. + */ + DisplayModePtr + (*get_modes)(xf86OutputPtr output); + +#ifdef RANDR_12_INTERFACE + /** + * Callback when an output's property has changed. + */ + Bool + (*set_property)(xf86OutputPtr output, + Atom property, + RRPropertyValuePtr value); +#endif + /** + * Clean up driver-specific bits of the output + */ + void + (*destroy) (xf86OutputPtr output); +} xf86OutputFuncsRec, *xf86OutputFuncsPtr; + +struct _xf86Output { + /** + * Associated ScrnInfo + */ + ScrnInfoPtr scrn; + + /** + * Currently connected crtc (if any) + * + * If this output is not in use, this field will be NULL. + */ + xf86CrtcPtr crtc; + + /** + * Possible CRTCs for this output as a mask of crtc indices + */ + CARD32 possible_crtcs; + + /** + * Possible outputs to share the same CRTC as a mask of output indices + */ + CARD32 possible_clones; + + /** + * Whether this output can support interlaced modes + */ + Bool interlaceAllowed; + + /** + * Whether this output can support double scan modes + */ + Bool doubleScanAllowed; + + /** + * List of available modes on this output. + * + * This should be the list from get_modes(), plus perhaps additional + * compatible modes added later. + */ + DisplayModePtr probed_modes; + + /** + * Options parsed from the related monitor section + */ + OptionInfoPtr options; + + /** + * Configured monitor section + */ + XF86ConfMonitorPtr conf_monitor; + + /** + * Desired initial position + */ + int initial_x, initial_y; + + /** + * Desired initial rotation + */ + Rotation initial_rotation; + + /** + * Current connection status + * + * This indicates whether a monitor is known to be connected + * to this output or not, or whether there is no way to tell + */ + xf86OutputStatus status; + + /** EDID monitor information */ + xf86MonPtr MonInfo; + + /** subpixel order */ + int subpixel_order; + + /** Physical size of the currently attached output device. */ + int mm_width, mm_height; + + /** Output name */ + char *name; + + /** output-specific functions */ + const xf86OutputFuncsRec *funcs; + + /** driver private information */ + void *driver_private; + +#ifdef RANDR_12_INTERFACE + /** + * RandR 1.2 output structure. + * + * When RandR 1.2 is available, this points at the associated + * RandR output structure and is created when this output is created + */ + RROutputPtr randr_output; +#else + void *randr_output; +#endif +}; + +typedef struct _xf86CrtcConfigFuncs { + /** + * Requests that the driver resize the screen. + * + * The driver is responsible for updating scrn->virtualX and scrn->virtualY. + * If the requested size cannot be set, the driver should leave those values + * alone and return FALSE. + * + * A naive driver that cannot reallocate the screen may simply change + * virtual[XY]. A more advanced driver will want to also change the + * devPrivate.ptr and devKind of the screen pixmap, update any offscreen + * pixmaps it may have moved, and change pScrn->displayWidth. + */ + Bool + (*resize)(ScrnInfoPtr scrn, + int width, + int height); +} xf86CrtcConfigFuncsRec, *xf86CrtcConfigFuncsPtr; + +typedef struct _xf86CrtcConfig { + int num_output; + xf86OutputPtr *output; + /** + * compat_output is used whenever we deal + * with legacy code that only understands a single + * output. pScrn->modes will be loaded from this output, + * adjust frame will whack this output, etc. + */ + int compat_output; + + int num_crtc; + xf86CrtcPtr *crtc; + + int minWidth, minHeight; + int maxWidth, maxHeight; + + /* For crtc-based rotation */ + DamagePtr rotation_damage; + Bool rotation_damage_registered; + + /* DGA */ + unsigned int dga_flags; + unsigned long dga_address; + DGAModePtr dga_modes; + int dga_nmode; + int dga_width, dga_height, dga_stride; + DisplayModePtr dga_save_mode; + + const xf86CrtcConfigFuncsRec *funcs; + + CreateScreenResourcesProcPtr CreateScreenResources; + + CloseScreenProcPtr CloseScreen; + + /* Cursor information */ + xf86CursorInfoPtr cursor_info; + CursorPtr cursor; + CARD8 *cursor_image; + Bool cursor_on; + CARD32 cursor_fg, cursor_bg; +} xf86CrtcConfigRec, *xf86CrtcConfigPtr; + +extern int xf86CrtcConfigPrivateIndex; + +#define XF86_CRTC_CONFIG_PTR(p) ((xf86CrtcConfigPtr) ((p)->privates[xf86CrtcConfigPrivateIndex].ptr)) + +/* + * Initialize xf86CrtcConfig structure + */ + +void +xf86CrtcConfigInit (ScrnInfoPtr scrn, + const xf86CrtcConfigFuncsRec *funcs); + +void +xf86CrtcSetSizeRange (ScrnInfoPtr scrn, + int minWidth, int minHeight, + int maxWidth, int maxHeight); + +/* + * Crtc functions + */ +xf86CrtcPtr +xf86CrtcCreate (ScrnInfoPtr scrn, + const xf86CrtcFuncsRec *funcs); + +void +xf86CrtcDestroy (xf86CrtcPtr crtc); + + +/** + * Sets the given video mode on the given crtc + */ +Bool +xf86CrtcSetMode (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, + int x, int y); + +/* + * Assign crtc rotation during mode set + */ +Bool +xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation); + +/* + * Clean up rotation during CloseScreen + */ +void +xf86RotateCloseScreen (ScreenPtr pScreen); + +/** + * Return whether any output is assigned to the crtc + */ +Bool +xf86CrtcInUse (xf86CrtcPtr crtc); + +/* + * Output functions + */ +xf86OutputPtr +xf86OutputCreate (ScrnInfoPtr scrn, + const xf86OutputFuncsRec *funcs, + const char *name); + +Bool +xf86OutputRename (xf86OutputPtr output, const char *name); + +void +xf86OutputDestroy (xf86OutputPtr output); + +void +xf86ProbeOutputModes (ScrnInfoPtr pScrn, int maxX, int maxY); + +void +xf86SetScrnInfoModes (ScrnInfoPtr pScrn); + +Bool +xf86CrtcScreenInit (ScreenPtr pScreen); + +Bool +xf86InitialConfiguration (ScrnInfoPtr pScrn, Bool canGrow); + +void +xf86DPMSSet(ScrnInfoPtr pScrn, int PowerManagementMode, int flags); + +Bool +xf86SaveScreen(ScreenPtr pScreen, int mode); + +void +xf86DisableUnusedFunctions(ScrnInfoPtr pScrn); + +DisplayModePtr +xf86OutputFindClosestMode (xf86OutputPtr output, DisplayModePtr desired); + +Bool +xf86SetSingleMode (ScrnInfoPtr pScrn, DisplayModePtr desired, Rotation rotation); + +/** + * Set the EDID information for the specified output + */ +void +xf86OutputSetEDID (xf86OutputPtr output, xf86MonPtr edid_mon); + +/** + * Return the list of modes supported by the EDID information + * stored in 'output' + */ +DisplayModePtr +xf86OutputGetEDIDModes (xf86OutputPtr output); + +xf86MonPtr +xf86OutputGetEDID (xf86OutputPtr output, I2CBusPtr pDDCBus); + +/** + * Initialize dga for this screen + */ + +Bool +xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address); + +/** + * Re-initialize dga for this screen (as when the set of modes changes) + */ + +Bool +xf86DiDGAReInit (ScreenPtr pScreen); + +/* + * Set the subpixel order reported for the screen using + * the information from the outputs + */ + +void +xf86CrtcSetScreenSubpixelOrder (ScreenPtr pScreen); + +/* + * Get a standard string name for a connector type + */ +char * +xf86ConnectorGetName(xf86ConnectorType connector); + +/* + * Using the desired mode information in each crtc, set + * modes (used in EnterVT functions, or at server startup) + */ + +Bool +xf86SetDesiredModes (ScrnInfoPtr pScrn); + +/** + * Initialize the CRTC-based cursor code. CRTC function vectors must + * contain relevant cursor setting functions. + * + * Driver should call this from ScreenInit function + */ +Bool +xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags); + +/** + * Called when anything on the screen is reconfigured. + * + * Reloads cursor images as needed, then adjusts cursor positions. + * + * Driver should call this from crtc commit function. + */ +void +xf86_reload_cursors (ScreenPtr screen); + +/** + * Called from EnterVT to turn the cursors back on + */ +void +xf86_show_cursors (ScrnInfoPtr scrn); + +/** + * Called by the driver to turn cursors off + */ +void +xf86_hide_cursors (ScrnInfoPtr scrn); + +/** + * Clean up CRTC-based cursor code. Driver must call this at CloseScreen time. + */ +void +xf86_cursors_fini (ScreenPtr screen); + +#endif /* _XF86CRTC_H_ */ diff --git a/hw/xfree86/modes/xf86Cursors.c b/hw/xfree86/modes/xf86Cursors.c new file mode 100644 index 000000000..009cccf89 --- /dev/null +++ b/hw/xfree86/modes/xf86Cursors.c @@ -0,0 +1,607 @@ +/* + * Copyright © 2007 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include <stddef.h> +#include <string.h> +#include <stdio.h> + +#include "xf86.h" +#include "xf86DDC.h" +#include "xf86Crtc.h" +#include "xf86Modes.h" +#include "xf86RandR12.h" +#include "X11/extensions/render.h" +#define DPMS_SERVER +#include "X11/extensions/dpms.h" +#include "X11/Xatom.h" +#ifdef RENDER +#include "picturestr.h" +#endif +#include "cursorstr.h" + +/* + * Given a screen coordinate, rotate back to a cursor source coordinate + */ +static void +xf86_crtc_rotate_coord (Rotation rotation, + int width, + int height, + int x_dst, + int y_dst, + int *x_src, + int *y_src) +{ + if (rotation & RR_Reflect_X) + x_dst = width - x_dst - 1; + if (rotation & RR_Reflect_Y) + y_dst = height - y_dst - 1; + + switch (rotation & 0xf) { + case RR_Rotate_0: + *x_src = x_dst; + *y_src = y_dst; + break; + case RR_Rotate_90: + *x_src = height - y_dst - 1; + *y_src = x_dst; + break; + case RR_Rotate_180: + *x_src = width - x_dst - 1; + *y_src = height - y_dst - 1; + break; + case RR_Rotate_270: + *x_src = y_dst; + *y_src = width - x_dst - 1; + break; + } +} + +/* + * Convert an x coordinate to a position within the cursor bitmap + */ +static int +cursor_bitpos (int flags, int x, Bool mask) +{ + if (flags & HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK) + mask = !mask; + if (flags & HARDWARE_CURSOR_NIBBLE_SWAPPED) + x = (x & ~3) | (3 - (x & 3)); + if (flags & HARDWARE_CURSOR_BIT_ORDER_MSBFIRST) + x = (x & ~7) | (7 - (x & 7)); + if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_1) + x = (x << 1) + mask; + else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_8) + x = ((x & ~7) << 1) | (mask << 3) | (x & 7); + else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_16) + x = ((x & ~15) << 1) | (mask << 4) | (x & 15); + else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_32) + x = ((x & ~31) << 1) | (mask << 5) | (x & 31); + else if (flags & HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64) + x = ((x & ~63) << 1) | (mask << 6) | (x & 63); + return x; +} + +/* + * Fetch one bit from a cursor bitmap + */ +static CARD8 +get_bit (CARD8 *image, int stride, int flags, int x, int y, Bool mask) +{ + x = cursor_bitpos (flags, x, mask); + image += y * stride; + return (image[(x >> 3)] >> (x & 7)) & 1; +} + +/* + * Set one bit in a cursor bitmap + */ +static void +set_bit (CARD8 *image, int stride, int flags, int x, int y, Bool mask) +{ + x = cursor_bitpos (flags, x, mask); + image += y * stride; + image[(x >> 3)] |= 1 << (x & 7); +} + +/* + * Load a two color cursor into a driver that supports only ARGB cursors + */ +static void +xf86_crtc_convert_cursor_to_argb (xf86CrtcPtr crtc, unsigned char *src) +{ + ScrnInfoPtr scrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; + int x, y; + int xin, yin; + int stride = cursor_info->MaxWidth >> 2; + int flags = cursor_info->Flags; + CARD32 bits; + +#ifdef ARGB_CURSOR + crtc->cursor_argb = FALSE; +#endif + + for (y = 0; y < cursor_info->MaxHeight; y++) + for (x = 0; x < cursor_info->MaxWidth; x++) + { + xf86_crtc_rotate_coord (crtc->rotation, + cursor_info->MaxWidth, + cursor_info->MaxHeight, + x, y, &xin, &yin); + if (get_bit (src, stride, flags, xin, yin, TRUE) == + ((flags & HARDWARE_CURSOR_INVERT_MASK) == 0)) + { + if (get_bit (src, stride, flags, xin, yin, FALSE)) + bits = xf86_config->cursor_fg; + else + bits = xf86_config->cursor_bg; + } + else + bits = 0; + cursor_image[y * cursor_info->MaxWidth + x] = bits; + } + crtc->funcs->load_cursor_argb (crtc, cursor_image); +} + +/* + * Set the colors for a two-color cursor (ignore for ARGB cursors) + */ +static void +xf86_set_cursor_colors (ScrnInfoPtr scrn, int bg, int fg) +{ + ScreenPtr screen = scrn->pScreen; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + CursorPtr cursor = xf86_config->cursor; + int c; + CARD8 *bits = cursor ? cursor->devPriv[screen->myNum] : NULL; + + /* Save ARGB versions of these colors */ + xf86_config->cursor_fg = (CARD32) fg | 0xff000000; + xf86_config->cursor_bg = (CARD32) bg | 0xff000000; + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->enabled && !crtc->cursor_argb) + { + if (crtc->funcs->load_cursor_image) + crtc->funcs->set_cursor_colors (crtc, bg, fg); + else if (bits) + xf86_crtc_convert_cursor_to_argb (crtc, bits); + } + } +} + +static void +xf86_crtc_hide_cursor (xf86CrtcPtr crtc) +{ + if (crtc->cursor_shown) + { + crtc->funcs->hide_cursor (crtc); + crtc->cursor_shown = FALSE; + } +} + +void +xf86_hide_cursors (ScrnInfoPtr scrn) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + xf86_config->cursor_on = FALSE; + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->enabled) + xf86_crtc_hide_cursor (crtc); + } +} + +static void +xf86_crtc_show_cursor (xf86CrtcPtr crtc) +{ + if (!crtc->cursor_shown && crtc->cursor_in_range) + { + crtc->funcs->show_cursor (crtc); + crtc->cursor_shown = TRUE; + } +} + +void +xf86_show_cursors (ScrnInfoPtr scrn) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + xf86_config->cursor_on = TRUE; + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->enabled) + xf86_crtc_show_cursor (crtc); + } +} + +static void +xf86_crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y) +{ + ScrnInfoPtr scrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + DisplayModePtr mode = &crtc->mode; + int x_temp; + int y_temp; + Bool in_range; + + /* + * Move to crtc coordinate space + */ + x -= crtc->x; + y -= crtc->y; + + /* + * Rotate + */ + switch ((crtc->rotation) & 0xf) { + case RR_Rotate_0: + break; + case RR_Rotate_90: + x_temp = y; + y_temp = mode->VDisplay - cursor_info->MaxWidth - x; + x = x_temp; + y = y_temp; + break; + case RR_Rotate_180: + x_temp = mode->HDisplay - cursor_info->MaxWidth - x; + y_temp = mode->VDisplay - cursor_info->MaxHeight - y; + x = x_temp; + y = y_temp; + break; + case RR_Rotate_270: + x_temp = mode->HDisplay - cursor_info->MaxHeight - y; + y_temp = x; + x = x_temp; + y = y_temp; + break; + } + + /* + * Reflect + */ + if (crtc->rotation & RR_Reflect_X) + x = mode->HDisplay - cursor_info->MaxWidth - x; + if (crtc->rotation & RR_Reflect_Y) + y = mode->VDisplay - cursor_info->MaxHeight - y; + + /* + * Disable the cursor when it is outside the viewport + */ + in_range = TRUE; + if (x >= mode->HDisplay || y >= mode->VDisplay || + x <= -cursor_info->MaxWidth || y <= -cursor_info->MaxHeight) + { + in_range = FALSE; + x = 0; + y = 0; + } + + crtc->cursor_in_range = in_range; + + if (in_range) + { + crtc->funcs->set_cursor_position (crtc, x, y); + xf86_crtc_show_cursor (crtc); + } + else + xf86_crtc_hide_cursor (crtc); +} + +static void +xf86_set_cursor_position (ScrnInfoPtr scrn, int x, int y) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + /* undo what xf86HWCurs did to the coordinates */ + x += scrn->frameX0; + y += scrn->frameY0; + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->enabled) + xf86_crtc_set_cursor_position (crtc, x, y); + } +} + +/* + * Load a two-color cursor into a crtc, performing rotation as needed + */ +static void +xf86_crtc_load_cursor_image (xf86CrtcPtr crtc, CARD8 *src) +{ + ScrnInfoPtr scrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + CARD8 *cursor_image; + +#ifdef ARGB_CURSOR + crtc->cursor_argb = FALSE; +#endif + + if (crtc->rotation == RR_Rotate_0) + cursor_image = src; + else + { + int x, y; + int xin, yin; + int stride = cursor_info->MaxWidth >> 2; + int flags = cursor_info->Flags; + + cursor_image = xf86_config->cursor_image; + memset(cursor_image, 0, cursor_info->MaxWidth * stride); + + for (y = 0; y < cursor_info->MaxHeight; y++) + for (x = 0; x < cursor_info->MaxWidth; x++) + { + xf86_crtc_rotate_coord (crtc->rotation, + cursor_info->MaxWidth, + cursor_info->MaxHeight, + x, y, &xin, &yin); + if (get_bit(src, stride, flags, xin, yin, FALSE)) + set_bit(cursor_image, stride, flags, x, y, FALSE); + if (get_bit(src, stride, flags, xin, yin, TRUE)) + set_bit(cursor_image, stride, flags, x, y, TRUE); + } + } + crtc->funcs->load_cursor_image (crtc, cursor_image); +} + +/* + * Load a cursor image into all active CRTCs + */ +static void +xf86_load_cursor_image (ScrnInfoPtr scrn, unsigned char *src) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->enabled) + { + if (crtc->funcs->load_cursor_image) + xf86_crtc_load_cursor_image (crtc, src); + else if (crtc->funcs->load_cursor_argb) + xf86_crtc_convert_cursor_to_argb (crtc, src); + } + } +} + +static Bool +xf86_use_hw_cursor (ScreenPtr screen, CursorPtr cursor) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + + xf86_config->cursor = cursor; + + if (cursor->bits->width > cursor_info->MaxWidth || + cursor->bits->height> cursor_info->MaxHeight) + return FALSE; + + return TRUE; +} + +static Bool +xf86_use_hw_cursor_argb (ScreenPtr screen, CursorPtr cursor) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + + xf86_config->cursor = cursor; + + /* Make sure ARGB support is available */ + if ((cursor_info->Flags & HARDWARE_CURSOR_ARGB) == 0) + return FALSE; + + if (cursor->bits->width > cursor_info->MaxWidth || + cursor->bits->height> cursor_info->MaxHeight) + return FALSE; + + return TRUE; +} + +static void +xf86_crtc_load_cursor_argb (xf86CrtcPtr crtc, CursorPtr cursor) +{ + ScrnInfoPtr scrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info = xf86_config->cursor_info; + CARD32 *cursor_image = (CARD32 *) xf86_config->cursor_image; + CARD32 *cursor_source = (CARD32 *) cursor->bits->argb; + int x, y; + int xin, yin; + CARD32 bits; + int source_width = cursor->bits->width; + int source_height = cursor->bits->height; + int image_width = cursor_info->MaxWidth; + int image_height = cursor_info->MaxHeight; + + for (y = 0; y < image_height; y++) + for (x = 0; x < image_width; x++) + { + xf86_crtc_rotate_coord (crtc->rotation, image_width, image_height, + x, y, &xin, &yin); + if (xin < source_width && yin < source_height) + bits = cursor_source[yin * source_width + xin]; + else + bits = 0; + cursor_image[y * image_width + x] = bits; + } + + crtc->funcs->load_cursor_argb (crtc, cursor_image); +} + +static void +xf86_load_cursor_argb (ScrnInfoPtr scrn, CursorPtr cursor) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->enabled) + xf86_crtc_load_cursor_argb (crtc, cursor); + } +} + +Bool +xf86_cursors_init (ScreenPtr screen, int max_width, int max_height, int flags) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + xf86CursorInfoPtr cursor_info; + + cursor_info = xf86CreateCursorInfoRec(); + if (!cursor_info) + return FALSE; + + xf86_config->cursor_image = xalloc (max_width * max_height * 4); + + if (!xf86_config->cursor_image) + { + xf86DestroyCursorInfoRec (cursor_info); + return FALSE; + } + + xf86_config->cursor_info = cursor_info; + + cursor_info->MaxWidth = max_width; + cursor_info->MaxHeight = max_height; + cursor_info->Flags = flags; + + cursor_info->SetCursorColors = xf86_set_cursor_colors; + cursor_info->SetCursorPosition = xf86_set_cursor_position; + cursor_info->LoadCursorImage = xf86_load_cursor_image; + cursor_info->HideCursor = xf86_hide_cursors; + cursor_info->ShowCursor = xf86_show_cursors; + cursor_info->UseHWCursor = xf86_use_hw_cursor; +#ifdef ARGB_CURSOR + if (flags & HARDWARE_CURSOR_ARGB) + { + cursor_info->UseHWCursorARGB = xf86_use_hw_cursor_argb; + cursor_info->LoadCursorARGB = xf86_load_cursor_argb; + } +#endif + + xf86_config->cursor = NULL; + xf86_hide_cursors (scrn); + + return xf86InitCursor (screen, cursor_info); +} + +/** + * Called when anything on the screen is reconfigured. + * + * Reloads cursor images as needed, then adjusts cursor positions + */ + +void +xf86_reload_cursors (ScreenPtr screen) +{ + ScrnInfoPtr scrn; + xf86CrtcConfigPtr xf86_config; + xf86CursorInfoPtr cursor_info; + CursorPtr cursor; + int x, y; + + /* initial mode setting will not have set a screen yet */ + if (!screen) + return; + scrn = xf86Screens[screen->myNum]; + xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + /* make sure the cursor code has been initialized */ + cursor_info = xf86_config->cursor_info; + if (!cursor_info) + return; + + cursor = xf86_config->cursor; + GetSpritePosition (&x, &y); + if (!(cursor_info->Flags & HARDWARE_CURSOR_UPDATE_UNHIDDEN)) + (*cursor_info->HideCursor)(scrn); + + if (cursor) + { +#ifdef ARGB_CURSOR + if (cursor->bits->argb && cursor_info->LoadCursorARGB) + (*cursor_info->LoadCursorARGB) (scrn, cursor); + else +#endif + (*cursor_info->LoadCursorImage)(cursor_info->pScrn, + cursor->devPriv[screen->myNum]); + + (*cursor_info->SetCursorPosition)(cursor_info->pScrn, x, y); + (*cursor_info->ShowCursor)(cursor_info->pScrn); + } +} + +/** + * Clean up CRTC-based cursor code + */ +void +xf86_cursors_fini (ScreenPtr screen) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + if (xf86_config->cursor_info) + { + xf86DestroyCursorInfoRec (xf86_config->cursor_info); + xf86_config->cursor_info = NULL; + } + if (xf86_config->cursor_image) + { + xfree (xf86_config->cursor_image); + xf86_config->cursor_image = NULL; + } +} diff --git a/hw/xfree86/modes/xf86DiDGA.c b/hw/xfree86/modes/xf86DiDGA.c new file mode 100644 index 000000000..0964cefa7 --- /dev/null +++ b/hw/xfree86/modes/xf86DiDGA.c @@ -0,0 +1,286 @@ +/* + * 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include "xf86.h" +#include "xf86DDC.h" +#include "xf86_OSproc.h" +#include "dgaproc.h" +#include "xf86Crtc.h" +#include "xf86Modes.h" +#include "gcstruct.h" +#include "scrnintstr.h" +#include "windowstr.h" + +static Bool +xf86_dga_get_modes (ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + DGAModePtr modes, mode; + DisplayModePtr display_mode; + int bpp = scrn->bitsPerPixel >> 3; + int num; + + num = 0; + display_mode = scrn->modes; + while (display_mode) + { + num++; + display_mode = display_mode->next; + if (display_mode == scrn->modes) + break; + } + + if (!num) + return FALSE; + + modes = xalloc(num * sizeof(DGAModeRec)); + if (!modes) + return FALSE; + + num = 0; + display_mode = scrn->modes; + while (display_mode) + { + mode = modes + num++; + + mode->mode = display_mode; + mode->flags = DGA_CONCURRENT_ACCESS | DGA_PIXMAP_AVAILABLE; + mode->flags |= DGA_FILL_RECT | DGA_BLIT_RECT; + if (display_mode->Flags & V_DBLSCAN) + mode->flags |= DGA_DOUBLESCAN; + if (display_mode->Flags & V_INTERLACE) + mode->flags |= DGA_INTERLACED; + mode->byteOrder = scrn->imageByteOrder; + mode->depth = scrn->depth; + mode->bitsPerPixel = scrn->bitsPerPixel; + mode->red_mask = scrn->mask.red; + mode->green_mask = scrn->mask.green; + mode->blue_mask = scrn->mask.blue; + mode->visualClass = (bpp == 1) ? PseudoColor : TrueColor; + mode->viewportWidth = display_mode->HDisplay; + mode->viewportHeight = display_mode->VDisplay; + mode->xViewportStep = (bpp == 3) ? 2 : 1; + mode->yViewportStep = 1; + mode->viewportFlags = DGA_FLIP_RETRACE; + mode->offset = 0; + mode->address = (unsigned char *) xf86_config->dga_address; + mode->bytesPerScanline = xf86_config->dga_stride; + mode->imageWidth = xf86_config->dga_width; + mode->imageHeight = xf86_config->dga_height; + mode->pixmapWidth = mode->imageWidth; + mode->pixmapHeight = mode->imageHeight; + mode->maxViewportX = mode->imageWidth - mode->viewportWidth; + mode->maxViewportY = mode->imageHeight - mode->viewportHeight; + + display_mode = display_mode->next; + if (display_mode == scrn->modes) + break; + } + if (xf86_config->dga_modes) + xfree (xf86_config->dga_modes); + xf86_config->dga_nmode = num; + xf86_config->dga_modes = modes; + return TRUE; +} + +static Bool +xf86_dga_set_mode(ScrnInfoPtr scrn, DGAModePtr display_mode) +{ + ScreenPtr pScreen = scrn->pScreen; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + if (!display_mode) + { + if (xf86_config->dga_save_mode) + { + xf86SwitchMode(pScreen, xf86_config->dga_save_mode); + xf86_config->dga_save_mode = NULL; + } + } + else + { + if (!xf86_config->dga_save_mode) + { + xf86_config->dga_save_mode = scrn->currentMode; + xf86SwitchMode(pScreen, display_mode->mode); + } + } + return TRUE; +} + +static int +xf86_dga_get_viewport(ScrnInfoPtr scrn) +{ + return 0; +} + +static void +xf86_dga_set_viewport(ScrnInfoPtr scrn, int x, int y, int flags) +{ + scrn->AdjustFrame(scrn->pScreen->myNum, x, y, flags); +} + +static Bool +xf86_dga_get_drawable_and_gc (ScrnInfoPtr scrn, DrawablePtr *ppDrawable, GCPtr *ppGC) +{ + ScreenPtr pScreen = scrn->pScreen; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + PixmapPtr pPixmap; + GCPtr pGC; + + pPixmap = GetScratchPixmapHeader (pScreen, xf86_config->dga_width, xf86_config->dga_height, + scrn->depth, scrn->bitsPerPixel, xf86_config->dga_stride, + (char *) scrn->memPhysBase + scrn->fbOffset); + if (!pPixmap) + return FALSE; + pGC = GetScratchGC (scrn->depth, pScreen); + if (!pGC) + { + FreeScratchPixmapHeader (pPixmap); + return FALSE; + } + *ppDrawable = &pPixmap->drawable; + *ppGC = pGC; + return TRUE; +} + +static void +xf86_dga_release_drawable_and_gc (ScrnInfoPtr scrn, DrawablePtr pDrawable, GCPtr pGC) +{ + FreeScratchGC (pGC); + FreeScratchPixmapHeader ((PixmapPtr) pDrawable); +} + +static void +xf86_dga_fill_rect(ScrnInfoPtr scrn, int x, int y, int w, int h, unsigned long color) +{ + GCPtr pGC; + DrawablePtr pDrawable; + XID vals[1]; + xRectangle r; + + if (!xf86_dga_get_drawable_and_gc (scrn, &pDrawable, &pGC)) + return; + vals[0] = color; + ChangeGC (pGC, GCForeground, vals); + ValidateGC (pDrawable, pGC); + r.x = x; + r.y = y; + r.width = w; + r.height = h; + pGC->ops->PolyFillRect (pDrawable, pGC, 1, &r); + xf86_dga_release_drawable_and_gc (scrn, pDrawable, pGC); +} + +static void +xf86_dga_sync(ScrnInfoPtr scrn) +{ + ScreenPtr pScreen = scrn->pScreen; + WindowPtr pRoot = WindowTable [pScreen->myNum]; + char buffer[4]; + + pScreen->GetImage (&pRoot->drawable, 0, 0, 1, 1, ZPixmap, ~0L, buffer); +} + +static void +xf86_dga_blit_rect(ScrnInfoPtr scrn, int srcx, int srcy, int w, int h, int dstx, int dsty) +{ + DrawablePtr pDrawable; + GCPtr pGC; + + if (!xf86_dga_get_drawable_and_gc (scrn, &pDrawable, &pGC)) + return; + ValidateGC (pDrawable, pGC); + pGC->ops->CopyArea (pDrawable, pDrawable, pGC, srcx, srcy, w, h, dstx, dsty); + xf86_dga_release_drawable_and_gc (scrn, pDrawable, pGC); +} + +static Bool +xf86_dga_open_framebuffer(ScrnInfoPtr scrn, + char **name, + unsigned char **mem, int *size, int *offset, int *flags) +{ + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + *size = xf86_config->dga_stride * xf86_config->dga_height; + *mem = (unsigned char *) (xf86_config->dga_address); + *offset = 0; + *flags = DGA_NEED_ROOT; + + return TRUE; +} + +static void +xf86_dga_close_framebuffer(ScrnInfoPtr scrn) +{ +} + +static DGAFunctionRec xf86_dga_funcs = { + xf86_dga_open_framebuffer, + xf86_dga_close_framebuffer, + xf86_dga_set_mode, + xf86_dga_set_viewport, + xf86_dga_get_viewport, + xf86_dga_sync, + xf86_dga_fill_rect, + xf86_dga_blit_rect, + NULL +}; + +Bool +xf86DiDGAReInit (ScreenPtr pScreen) +{ + ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + if (!xf86_dga_get_modes (pScreen)) + return FALSE; + + return DGAReInitModes (pScreen, xf86_config->dga_modes, xf86_config->dga_nmode); +} + +Bool +xf86DiDGAInit (ScreenPtr pScreen, unsigned long dga_address) +{ + ScrnInfoPtr scrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + + xf86_config->dga_flags = 0; + xf86_config->dga_address = dga_address; + xf86_config->dga_width = scrn->virtualX; + xf86_config->dga_height = scrn->virtualY; + xf86_config->dga_stride = scrn->displayWidth * scrn->bitsPerPixel >> 3; + + if (!xf86_dga_get_modes (pScreen)) + return FALSE; + + return DGAInit(pScreen, &xf86_dga_funcs, xf86_config->dga_modes, xf86_config->dga_nmode); +} diff --git a/hw/xfree86/modes/xf86EdidModes.c b/hw/xfree86/modes/xf86EdidModes.c new file mode 100644 index 000000000..c4cf6870b --- /dev/null +++ b/hw/xfree86/modes/xf86EdidModes.c @@ -0,0 +1,490 @@ +/* + * Copyright 2006 Luc Verhaegen. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sub license, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * @file This is a copy of edid_modes.c from the X Server, for compatibility + * with old X Servers. + */ +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include "xf86.h" +#include "xf86DDC.h" +#include <X11/Xatom.h> +#include "property.h" +#include "propertyst.h" +#include "xf86DDC.h" +#include "xf86Crtc.h" +#include <string.h> +#include <math.h> + +/* + * Quirks to work around broken EDID data from various monitors. + */ + +typedef enum { + DDC_QUIRK_NONE = 0, + /* Force detailed sync polarity to -h +v */ + DDC_QUIRK_DT_SYNC_HM_VP = 1 << 0, + /* First detailed mode is bogus, prefer largest mode at 60hz */ + DDC_QUIRK_PREFER_LARGE_60 = 1 << 1, + /* 135MHz clock is too high, drop a bit */ + DDC_QUIRK_135_CLOCK_TOO_HIGH = 1 << 2 +} ddc_quirk_t; + +static Bool quirk_dt_sync_hm_vp (int scrnIndex, xf86MonPtr DDC) +{ + /* Belinea 1924S1W */ + if (memcmp (DDC->vendor.name, "MAX", 4) == 0 && + DDC->vendor.prod_id == 1932) + return TRUE; + /* Belinea 10 20 30W */ + if (memcmp (DDC->vendor.name, "MAX", 4) == 0 && + DDC->vendor.prod_id == 2007) + return TRUE; + /* ViewSonic VX2025wm (bug #9941) */ + if (memcmp (DDC->vendor.name, "VSC", 4) == 0 && + DDC->vendor.prod_id == 58653) + return TRUE; + + return FALSE; +} + +static Bool quirk_prefer_large_60 (int scrnIndex, xf86MonPtr DDC) +{ + /* Belinea 10 15 55 */ + if (memcmp (DDC->vendor.name, "MAX", 4) == 0 && + DDC->vendor.prod_id == 1516) + return TRUE; + + return FALSE; +} + +static Bool quirk_135_clock_too_high (int scrnIndex, xf86MonPtr DDC) +{ + /* Envision Peripherals, Inc. EN-7100e. See bug #9550. */ + if (memcmp (DDC->vendor.name, "EPI", 4) == 0 && + DDC->vendor.prod_id == 59264) + return TRUE; + + return FALSE; +} + +typedef struct { + Bool (*detect) (int scrnIndex, xf86MonPtr DDC); + ddc_quirk_t quirk; + char *description; +} ddc_quirk_map_t; + +static const ddc_quirk_map_t ddc_quirks[] = { + { + quirk_dt_sync_hm_vp, DDC_QUIRK_DT_SYNC_HM_VP, + "Set detailed timing sync polarity to -h +v" + }, + { + quirk_prefer_large_60, DDC_QUIRK_PREFER_LARGE_60, + "Detailed timing is not preferred, use largest mode at 60Hz" + }, + { + quirk_135_clock_too_high, DDC_QUIRK_135_CLOCK_TOO_HIGH, + "Recommended 135MHz pixel clock is too high" + }, + { + NULL, DDC_QUIRK_NONE, + "No known quirks" + }, +}; + +/* + * TODO: + * - for those with access to the VESA DMT standard; review please. + */ +#define MODEPREFIX(name) NULL, NULL, name, 0,M_T_DRIVER +#define MODESUFFIX 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,FALSE,FALSE,0,NULL,0,0.0,0.0 + +static DisplayModeRec DDCEstablishedModes[17] = { + { MODEPREFIX("800x600"), 40000, 800, 840, 968, 1056, 0, 600, 601, 605, 628, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@60Hz */ + { MODEPREFIX("800x600"), 36000, 800, 824, 896, 1024, 0, 600, 601, 603, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@56Hz */ + { MODEPREFIX("640x480"), 31500, 640, 656, 720, 840, 0, 480, 481, 484, 500, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@75Hz */ + { MODEPREFIX("640x480"), 31500, 640, 664, 704, 832, 0, 480, 489, 491, 520, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@72Hz */ + { MODEPREFIX("640x480"), 30240, 640, 704, 768, 864, 0, 480, 483, 486, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@67Hz */ + { MODEPREFIX("640x480"), 25200, 640, 656, 752, 800, 0, 480, 490, 492, 525, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 640x480@60Hz */ + { MODEPREFIX("720x400"), 35500, 720, 738, 846, 900, 0, 400, 421, 423, 449, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 720x400@88Hz */ + { MODEPREFIX("720x400"), 28320, 720, 738, 846, 900, 0, 400, 412, 414, 449, 0, V_NHSYNC | V_PVSYNC, MODESUFFIX }, /* 720x400@70Hz */ + { MODEPREFIX("1280x1024"), 135000, 1280, 1296, 1440, 1688, 0, 1024, 1025, 1028, 1066, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1280x1024@75Hz */ + { MODEPREFIX("1024x768"), 78800, 1024, 1040, 1136, 1312, 0, 768, 769, 772, 800, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1024x768@75Hz */ + { MODEPREFIX("1024x768"), 75000, 1024, 1048, 1184, 1328, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768@70Hz */ + { MODEPREFIX("1024x768"), 65000, 1024, 1048, 1184, 1344, 0, 768, 771, 777, 806, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 1024x768@60Hz */ + { MODEPREFIX("1024x768"), 44900, 1024, 1032, 1208, 1264, 0, 768, 768, 776, 817, 0, V_PHSYNC | V_PVSYNC | V_INTERLACE, MODESUFFIX }, /* 1024x768@43Hz */ + { MODEPREFIX("832x624"), 57284, 832, 864, 928, 1152, 0, 624, 625, 628, 667, 0, V_NHSYNC | V_NVSYNC, MODESUFFIX }, /* 832x624@75Hz */ + { MODEPREFIX("800x600"), 49500, 800, 816, 896, 1056, 0, 600, 601, 604, 625, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@75Hz */ + { MODEPREFIX("800x600"), 50000, 800, 856, 976, 1040, 0, 600, 637, 643, 666, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 800x600@72Hz */ + { MODEPREFIX("1152x864"), 108000, 1152, 1216, 1344, 1600, 0, 864, 865, 868, 900, 0, V_PHSYNC | V_PVSYNC, MODESUFFIX }, /* 1152x864@75Hz */ +}; + +static DisplayModePtr +DDCModesFromEstablished(int scrnIndex, struct established_timings *timing, + ddc_quirk_t quirks) +{ + DisplayModePtr Modes = NULL, Mode = NULL; + CARD32 bits = (timing->t1) | (timing->t2 << 8) | + ((timing->t_manu & 0x80) << 9); + int i; + + for (i = 0; i < 17; i++) { + if (bits & (0x01 << i)) { + Mode = xf86DuplicateMode(&DDCEstablishedModes[i]); + Modes = xf86ModesAdd(Modes, Mode); + } + } + + return Modes; +} + +/* + * + */ +static DisplayModePtr +DDCModesFromStandardTiming(int scrnIndex, struct std_timings *timing, + ddc_quirk_t quirks) +{ + DisplayModePtr Modes = NULL, Mode = NULL; + int i; + + for (i = 0; i < STD_TIMINGS; i++) { + if (timing[i].hsize && timing[i].vsize && timing[i].refresh) { + Mode = xf86CVTMode(timing[i].hsize, timing[i].vsize, + timing[i].refresh, FALSE, FALSE); + Mode->type = M_T_DRIVER; + Modes = xf86ModesAdd(Modes, Mode); + } + } + + return Modes; +} + +/* + * + */ +static DisplayModePtr +DDCModeFromDetailedTiming(int scrnIndex, struct detailed_timings *timing, + int preferred, ddc_quirk_t quirks) +{ + DisplayModePtr Mode; + + /* We don't do stereo */ + if (timing->stereo) { + xf86DrvMsg(scrnIndex, X_INFO, + "%s: Ignoring: We don't handle stereo.\n", __func__); + return NULL; + } + + /* We only do seperate sync currently */ + if (timing->sync != 0x03) { + xf86DrvMsg(scrnIndex, X_INFO, + "%s: %dx%d Warning: We only handle seperate" + " sync.\n", __func__, timing->h_active, timing->v_active); + } + + Mode = xnfalloc(sizeof(DisplayModeRec)); + memset(Mode, 0, sizeof(DisplayModeRec)); + + Mode->type = M_T_DRIVER; + if (preferred) + Mode->type |= M_T_PREFERRED; + + if( ( quirks & DDC_QUIRK_135_CLOCK_TOO_HIGH ) && + timing->clock == 135000000 ) + Mode->Clock = 108880; + else + Mode->Clock = timing->clock / 1000.0; + + Mode->HDisplay = timing->h_active; + Mode->HSyncStart = timing->h_active + timing->h_sync_off; + Mode->HSyncEnd = Mode->HSyncStart + timing->h_sync_width; + Mode->HTotal = timing->h_active + timing->h_blanking; + + Mode->VDisplay = timing->v_active; + Mode->VSyncStart = timing->v_active + timing->v_sync_off; + Mode->VSyncEnd = Mode->VSyncStart + timing->v_sync_width; + Mode->VTotal = timing->v_active + timing->v_blanking; + + xf86SetModeDefaultName(Mode); + + /* We ignore h/v_size and h/v_border for now. */ + + if (timing->interlaced) + Mode->Flags |= V_INTERLACE; + + if (quirks & DDC_QUIRK_DT_SYNC_HM_VP) + Mode->Flags |= V_NHSYNC | V_PVSYNC; + else + { + if (timing->misc & 0x02) + Mode->Flags |= V_PHSYNC; + else + Mode->Flags |= V_NHSYNC; + + if (timing->misc & 0x01) + Mode->Flags |= V_PVSYNC; + else + Mode->Flags |= V_NVSYNC; + } + + return Mode; +} + +/* + * + */ +static void +DDCGuessRangesFromModes(int scrnIndex, MonPtr Monitor, DisplayModePtr Modes) +{ + DisplayModePtr Mode = Modes; + + if (!Monitor || !Modes) + return; + + /* set up the ranges for scanning through the modes */ + Monitor->nHsync = 1; + Monitor->hsync[0].lo = 1024.0; + Monitor->hsync[0].hi = 0.0; + + Monitor->nVrefresh = 1; + Monitor->vrefresh[0].lo = 1024.0; + Monitor->vrefresh[0].hi = 0.0; + + while (Mode) { + if (!Mode->HSync) + Mode->HSync = ((float) Mode->Clock ) / ((float) Mode->HTotal); + + if (!Mode->VRefresh) + Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) / + ((float) (Mode->HTotal * Mode->VTotal)); + + if (Mode->HSync < Monitor->hsync[0].lo) + Monitor->hsync[0].lo = Mode->HSync; + + if (Mode->HSync > Monitor->hsync[0].hi) + Monitor->hsync[0].hi = Mode->HSync; + + if (Mode->VRefresh < Monitor->vrefresh[0].lo) + Monitor->vrefresh[0].lo = Mode->VRefresh; + + if (Mode->VRefresh > Monitor->vrefresh[0].hi) + Monitor->vrefresh[0].hi = Mode->VRefresh; + + Mode = Mode->next; + } +} + +DisplayModePtr +xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC) +{ + int preferred, i; + DisplayModePtr Modes = NULL, Mode; + ddc_quirk_t quirks; + + xf86DrvMsg (scrnIndex, X_INFO, "EDID vendor \"%s\", prod id %d\n", + DDC->vendor.name, DDC->vendor.prod_id); + quirks = DDC_QUIRK_NONE; + for (i = 0; ddc_quirks[i].detect; i++) + if (ddc_quirks[i].detect (scrnIndex, DDC)) + { + xf86DrvMsg (scrnIndex, X_INFO, " EDID quirk: %s\n", + ddc_quirks[i].description); + quirks |= ddc_quirks[i].quirk; + } + + preferred = PREFERRED_TIMING_MODE(DDC->features.msc); + if (quirks & DDC_QUIRK_PREFER_LARGE_60) + preferred = 0; + + for (i = 0; i < DET_TIMINGS; i++) { + struct detailed_monitor_section *det_mon = &DDC->det_mon[i]; + + switch (det_mon->type) { + case DT: + Mode = DDCModeFromDetailedTiming(scrnIndex, + &det_mon->section.d_timings, + preferred, + quirks); + preferred = 0; + Modes = xf86ModesAdd(Modes, Mode); + break; + case DS_STD_TIMINGS: + Mode = DDCModesFromStandardTiming(scrnIndex, + det_mon->section.std_t, + quirks); + Modes = xf86ModesAdd(Modes, Mode); + break; + default: + break; + } + } + + /* Add established timings */ + Mode = DDCModesFromEstablished(scrnIndex, &DDC->timings1, quirks); + Modes = xf86ModesAdd(Modes, Mode); + + /* Add standard timings */ + Mode = DDCModesFromStandardTiming(scrnIndex, DDC->timings2, quirks); + Modes = xf86ModesAdd(Modes, Mode); + + if (quirks & DDC_QUIRK_PREFER_LARGE_60) + { + DisplayModePtr best = Modes; + for (Mode = Modes; Mode; Mode = Mode->next) + { + if (Mode == best) continue; + if (Mode->HDisplay * Mode->VDisplay > best->HDisplay * best->VDisplay) + { + best = Mode; + continue; + } + if (Mode->HDisplay * Mode->VDisplay == best->HDisplay * best->VDisplay) + { + double mode_refresh = xf86ModeVRefresh (Mode); + double best_refresh = xf86ModeVRefresh (best); + double mode_dist = fabs(mode_refresh - 60.0); + double best_dist = fabs(best_refresh - 60.0); + if (mode_dist < best_dist) + { + best = Mode; + continue; + } + } + } + if (best) + best->type |= M_T_PREFERRED; + } + return Modes; +} + +/* + * Fill out MonPtr with xf86MonPtr information. + */ +void +xf86DDCMonitorSet(int scrnIndex, MonPtr Monitor, xf86MonPtr DDC) +{ + DisplayModePtr Modes = NULL, Mode; + int i, clock; + Bool have_hsync = FALSE, have_vrefresh = FALSE; + + if (!Monitor || !DDC) + return; + + Monitor->DDC = DDC; + + Monitor->widthmm = 10 * DDC->features.hsize; + Monitor->heightmm = 10 * DDC->features.vsize; + + /* If this is a digital display, then we can use reduced blanking */ + if (DDC->features.input_type) + Monitor->reducedblanking = TRUE; + /* Allow the user to also enable this through config */ + + Modes = xf86DDCGetModes(scrnIndex, DDC); + + /* Skip EDID ranges if they were specified in the config file */ + have_hsync = (Monitor->nHsync != 0); + have_vrefresh = (Monitor->nVrefresh != 0); + + /* Go through the detailed monitor sections */ + for (i = 0; i < DET_TIMINGS; i++) { + switch (DDC->det_mon[i].type) { + case DS_RANGES: + if (!have_hsync) { + if (!Monitor->nHsync) + xf86DrvMsg(scrnIndex, X_INFO, + "Using EDID range info for horizontal sync\n"); + Monitor->hsync[Monitor->nHsync].lo = + DDC->det_mon[i].section.ranges.min_h; + Monitor->hsync[Monitor->nHsync].hi = + DDC->det_mon[i].section.ranges.max_h; + Monitor->nHsync++; + } else { + xf86DrvMsg(scrnIndex, X_INFO, + "Using hsync ranges from config file\n"); + } + + if (!have_vrefresh) { + if (!Monitor->nVrefresh) + xf86DrvMsg(scrnIndex, X_INFO, + "Using EDID range info for vertical refresh\n"); + Monitor->vrefresh[Monitor->nVrefresh].lo = + DDC->det_mon[i].section.ranges.min_v; + Monitor->vrefresh[Monitor->nVrefresh].hi = + DDC->det_mon[i].section.ranges.max_v; + Monitor->nVrefresh++; + } else { + xf86DrvMsg(scrnIndex, X_INFO, + "Using vrefresh ranges from config file\n"); + } + + clock = DDC->det_mon[i].section.ranges.max_clock * 1000; + if (clock > Monitor->maxPixClock) + Monitor->maxPixClock = clock; + + break; + default: + break; + } + } + + if (Modes) { + /* Print Modes */ + xf86DrvMsg(scrnIndex, X_INFO, "Printing DDC gathered Modelines:\n"); + + Mode = Modes; + while (Mode) { + xf86PrintModeline(scrnIndex, Mode); + Mode = Mode->next; + } + + /* Do we still need ranges to be filled in? */ + if (!Monitor->nHsync || !Monitor->nVrefresh) + DDCGuessRangesFromModes(scrnIndex, Monitor, Modes); + + /* look for last Mode */ + Mode = Modes; + + while (Mode->next) + Mode = Mode->next; + + /* add to MonPtr */ + if (Monitor->Modes) { + Monitor->Last->next = Modes; + Modes->prev = Monitor->Last; + Monitor->Last = Mode; + } else { + Monitor->Modes = Modes; + Monitor->Last = Mode; + } + } +} diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c new file mode 100644 index 000000000..5b52bd76c --- /dev/null +++ b/hw/xfree86/modes/xf86Modes.c @@ -0,0 +1,664 @@ +/* -*- c-basic-offset: 4 -*- */ +/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86Mode.c,v 1.10 2006/03/07 16:00:57 libv Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86Mode.c,v 1.69 2003/10/08 14:58:28 dawes Exp $ */ +/* + * Copyright (c) 1997-2003 by The XFree86 Project, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the copyright holder(s) + * and author(s) shall not be used in advertising or otherwise to promote + * the sale, use or other dealings in this Software without prior written + * authorization from the copyright holder(s) and author(s). + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include "xf86Modes.h" +#include "xf86Priv.h" + +extern XF86ConfigPtr xf86configptr; + +/** + * @file this file contains symbols from xf86Mode.c and friends that are static + * there but we still want to use. We need to come up with better API here. + */ + +#if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,2,99,2,0) +/** + * Calculates the horizontal sync rate of a mode. + * + * Exact copy of xf86Mode.c's. + */ +double +xf86ModeHSync(DisplayModePtr mode) +{ + double hsync = 0.0; + + if (mode->HSync > 0.0) + hsync = mode->HSync; + else if (mode->HTotal > 0) + hsync = (float)mode->Clock / (float)mode->HTotal; + + return hsync; +} + +/** + * Calculates the vertical refresh rate of a mode. + * + * Exact copy of xf86Mode.c's. + */ +double +xf86ModeVRefresh(DisplayModePtr mode) +{ + double refresh = 0.0; + + if (mode->VRefresh > 0.0) + refresh = mode->VRefresh; + else if (mode->HTotal > 0 && mode->VTotal > 0) { + refresh = mode->Clock * 1000.0 / mode->HTotal / mode->VTotal; + if (mode->Flags & V_INTERLACE) + refresh *= 2.0; + if (mode->Flags & V_DBLSCAN) + refresh /= 2.0; + if (mode->VScan > 1) + refresh /= (float)(mode->VScan); + } + return refresh; +} + +int +xf86ModeWidth (DisplayModePtr mode, Rotation rotation) +{ + switch (rotation & 0xf) { + case RR_Rotate_0: + case RR_Rotate_180: + return mode->HDisplay; + case RR_Rotate_90: + case RR_Rotate_270: + return mode->VDisplay; + default: + return 0; + } +} + +int +xf86ModeHeight (DisplayModePtr mode, Rotation rotation) +{ + switch (rotation & 0xf) { + case RR_Rotate_0: + case RR_Rotate_180: + return mode->VDisplay; + case RR_Rotate_90: + case RR_Rotate_270: + return mode->HDisplay; + default: + return 0; + } +} + +/** Sets a default mode name of <width>x<height> on a mode. */ +void +xf86SetModeDefaultName(DisplayModePtr mode) +{ + if (mode->name != NULL) + xfree(mode->name); + + mode->name = XNFprintf("%dx%d", mode->HDisplay, mode->VDisplay); +} + +/* + * xf86SetModeCrtc + * + * Initialises the Crtc parameters for a mode. The initialisation includes + * adjustments for interlaced and double scan modes. + * + * Exact copy of xf86Mode.c's. + */ +void +xf86SetModeCrtc(DisplayModePtr p, int adjustFlags) +{ + if ((p == NULL) || ((p->type & M_T_CRTC_C) == M_T_BUILTIN)) + return; + + p->CrtcHDisplay = p->HDisplay; + p->CrtcHSyncStart = p->HSyncStart; + p->CrtcHSyncEnd = p->HSyncEnd; + p->CrtcHTotal = p->HTotal; + p->CrtcHSkew = p->HSkew; + p->CrtcVDisplay = p->VDisplay; + p->CrtcVSyncStart = p->VSyncStart; + p->CrtcVSyncEnd = p->VSyncEnd; + p->CrtcVTotal = p->VTotal; + if (p->Flags & V_INTERLACE) { + if (adjustFlags & INTERLACE_HALVE_V) { + p->CrtcVDisplay /= 2; + p->CrtcVSyncStart /= 2; + p->CrtcVSyncEnd /= 2; + p->CrtcVTotal /= 2; + } + /* Force interlaced modes to have an odd VTotal */ + /* maybe we should only do this when INTERLACE_HALVE_V is set? */ + p->CrtcVTotal |= 1; + } + + if (p->Flags & V_DBLSCAN) { + p->CrtcVDisplay *= 2; + p->CrtcVSyncStart *= 2; + p->CrtcVSyncEnd *= 2; + p->CrtcVTotal *= 2; + } + if (p->VScan > 1) { + p->CrtcVDisplay *= p->VScan; + p->CrtcVSyncStart *= p->VScan; + p->CrtcVSyncEnd *= p->VScan; + p->CrtcVTotal *= p->VScan; + } + p->CrtcVBlankStart = min(p->CrtcVSyncStart, p->CrtcVDisplay); + p->CrtcVBlankEnd = max(p->CrtcVSyncEnd, p->CrtcVTotal); + p->CrtcHBlankStart = min(p->CrtcHSyncStart, p->CrtcHDisplay); + p->CrtcHBlankEnd = max(p->CrtcHSyncEnd, p->CrtcHTotal); + + p->CrtcHAdjusted = FALSE; + p->CrtcVAdjusted = FALSE; +} + +/** + * Allocates and returns a copy of pMode, including pointers within pMode. + */ +DisplayModePtr +xf86DuplicateMode(DisplayModePtr pMode) +{ + DisplayModePtr pNew; + + pNew = xnfalloc(sizeof(DisplayModeRec)); + *pNew = *pMode; + pNew->next = NULL; + pNew->prev = NULL; + if (pNew->name == NULL) { + xf86SetModeDefaultName(pMode); + } else { + pNew->name = xnfstrdup(pMode->name); + } + + return pNew; +} + +/** + * Duplicates every mode in the given list and returns a pointer to the first + * mode. + * + * \param modeList doubly-linked mode list + */ +DisplayModePtr +xf86DuplicateModes(ScrnInfoPtr pScrn, DisplayModePtr modeList) +{ + DisplayModePtr first = NULL, last = NULL; + DisplayModePtr mode; + + for (mode = modeList; mode != NULL; mode = mode->next) { + DisplayModePtr new; + + new = xf86DuplicateMode(mode); + + /* Insert pNew into modeList */ + if (last) { + last->next = new; + new->prev = last; + } else { + first = new; + new->prev = NULL; + } + new->next = NULL; + last = new; + } + + return first; +} + +/** + * Returns true if the given modes should program to the same timings. + * + * This doesn't use Crtc values, as it might be used on ModeRecs without the + * Crtc values set. So, it's assumed that the other numbers are enough. + * + * This isn't in xf86Modes.c, but it might deserve to be there. + */ +Bool +xf86ModesEqual(DisplayModePtr pMode1, DisplayModePtr pMode2) +{ + if (pMode1->Clock == pMode2->Clock && + pMode1->HDisplay == pMode2->HDisplay && + pMode1->HSyncStart == pMode2->HSyncStart && + pMode1->HSyncEnd == pMode2->HSyncEnd && + pMode1->HTotal == pMode2->HTotal && + pMode1->HSkew == pMode2->HSkew && + pMode1->VDisplay == pMode2->VDisplay && + pMode1->VSyncStart == pMode2->VSyncStart && + pMode1->VSyncEnd == pMode2->VSyncEnd && + pMode1->VTotal == pMode2->VTotal && + pMode1->VScan == pMode2->VScan && + pMode1->Flags == pMode2->Flags) + { + return TRUE; + } else { + return FALSE; + } +} + +/* exact copy of xf86Mode.c */ +static void +add(char **p, char *new) +{ + *p = xnfrealloc(*p, strlen(*p) + strlen(new) + 2); + strcat(*p, " "); + strcat(*p, new); +} + +/** + * Print out a modeline. + * + * Convenient VRefresh printing was added, though, compared to xf86Mode.c + */ +void +xf86PrintModeline(int scrnIndex,DisplayModePtr mode) +{ + char tmp[256]; + char *flags = xnfcalloc(1, 1); + + if (mode->HSkew) { + snprintf(tmp, 256, "hskew %i", mode->HSkew); + add(&flags, tmp); + } + if (mode->VScan) { + snprintf(tmp, 256, "vscan %i", mode->VScan); + add(&flags, tmp); + } + if (mode->Flags & V_INTERLACE) add(&flags, "interlace"); + if (mode->Flags & V_CSYNC) add(&flags, "composite"); + if (mode->Flags & V_DBLSCAN) add(&flags, "doublescan"); + if (mode->Flags & V_BCAST) add(&flags, "bcast"); + if (mode->Flags & V_PHSYNC) add(&flags, "+hsync"); + if (mode->Flags & V_NHSYNC) add(&flags, "-hsync"); + if (mode->Flags & V_PVSYNC) add(&flags, "+vsync"); + if (mode->Flags & V_NVSYNC) add(&flags, "-vsync"); + if (mode->Flags & V_PCSYNC) add(&flags, "+csync"); + if (mode->Flags & V_NCSYNC) add(&flags, "-csync"); +#if 0 + if (mode->Flags & V_CLKDIV2) add(&flags, "vclk/2"); +#endif + xf86DrvMsg(scrnIndex, X_INFO, + "Modeline \"%s\"x%.01f %6.2f %i %i %i %i %i %i %i %i%s " + "(%.01f kHz)\n", + mode->name, mode->VRefresh, mode->Clock/1000., mode->HDisplay, + mode->HSyncStart, mode->HSyncEnd, mode->HTotal, + mode->VDisplay, mode->VSyncStart, mode->VSyncEnd, + mode->VTotal, flags, xf86ModeHSync(mode)); + xfree(flags); +} +#endif /* XORG_VERSION_CURRENT <= 7.2.99.2 */ + +/** + * Marks as bad any modes with unsupported flags. + * + * \param modeList doubly-linked or circular list of modes. + * \param flags flags supported by the driver. + * + * \bug only V_INTERLACE and V_DBLSCAN are supported. Is that enough? + * + * This is not in xf86Modes.c, but would be part of the proposed new API. + */ +void +xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int flags) +{ + DisplayModePtr mode; + + for (mode = modeList; mode != NULL; mode = mode->next) { + if (mode->Flags & V_INTERLACE && !(flags & V_INTERLACE)) + mode->status = MODE_NO_INTERLACE; + if (mode->Flags & V_DBLSCAN && !(flags & V_DBLSCAN)) + mode->status = MODE_NO_DBLESCAN; + } +} + +/** + * Marks as bad any modes extending beyond the given max X, Y, or pitch. + * + * \param modeList doubly-linked or circular list of modes. + * + * This is not in xf86Modes.c, but would be part of the proposed new API. + */ +void +xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int maxX, int maxY, int maxPitch) +{ + DisplayModePtr mode; + + for (mode = modeList; mode != NULL; mode = mode->next) { + if (maxPitch > 0 && mode->HDisplay > maxPitch) + mode->status = MODE_BAD_WIDTH; + + if (maxX > 0 && mode->HDisplay > maxX) + mode->status = MODE_VIRTUAL_X; + + if (maxY > 0 && mode->VDisplay > maxY) + mode->status = MODE_VIRTUAL_Y; + + if (mode->next == modeList) + break; + } +} + +/** + * Marks as bad any modes that aren't supported by the given monitor's + * hsync and vrefresh ranges. + * + * \param modeList doubly-linked or circular list of modes. + * + * This is not in xf86Modes.c, but would be part of the proposed new API. + */ +void +xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, + MonPtr mon) +{ + DisplayModePtr mode; + + for (mode = modeList; mode != NULL; mode = mode->next) { + Bool bad; + int i; + + bad = TRUE; + for (i = 0; i < mon->nHsync; i++) { + if (xf86ModeHSync(mode) >= mon->hsync[i].lo && + xf86ModeHSync(mode) <= mon->hsync[i].hi) + { + bad = FALSE; + } + } + if (bad) + mode->status = MODE_HSYNC; + + bad = TRUE; + for (i = 0; i < mon->nVrefresh; i++) { + if (xf86ModeVRefresh(mode) >= mon->vrefresh[i].lo && + xf86ModeVRefresh(mode) <= mon->vrefresh[i].hi) + { + bad = FALSE; + } + } + if (bad) + mode->status = MODE_VSYNC; + + if (mode->next == modeList) + break; + } +} + +/** + * Marks as bad any modes extending beyond outside of the given clock ranges. + * + * \param modeList doubly-linked or circular list of modes. + * \param min pointer to minimums of clock ranges + * \param max pointer to maximums of clock ranges + * \param n_ranges number of ranges. + * + * This is not in xf86Modes.c, but would be part of the proposed new API. + */ +void +xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int *min, int *max, int n_ranges) +{ + DisplayModePtr mode; + int i; + + for (mode = modeList; mode != NULL; mode = mode->next) { + Bool good = FALSE; + for (i = 0; i < n_ranges; i++) { + if (mode->Clock >= min[i] && mode->Clock <= max[i]) { + good = TRUE; + break; + } + } + if (!good) + mode->status = MODE_CLOCK_RANGE; + } +} + +/** + * If the user has specified a set of mode names to use, mark as bad any modes + * not listed. + * + * The user mode names specified are prefixes to names of modes, so "1024x768" + * will match modes named "1024x768", "1024x768x75", "1024x768-good", but + * "1024x768x75" would only match "1024x768x75" from that list. + * + * MODE_BAD is used as the rejection flag, for lack of a better flag. + * + * \param modeList doubly-linked or circular list of modes. + * + * This is not in xf86Modes.c, but would be part of the proposed new API. + */ +void +xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList) +{ + DisplayModePtr mode; + + if (pScrn->display->modes[0] == NULL) + return; + + for (mode = modeList; mode != NULL; mode = mode->next) { + int i; + Bool good = FALSE; + + for (i = 0; pScrn->display->modes[i] != NULL; i++) { + if (strncmp(pScrn->display->modes[i], mode->name, + strlen(pScrn->display->modes[i])) == 0) { + good = TRUE; + break; + } + } + if (!good) + mode->status = MODE_BAD; + } +} + + +/** + * Frees any modes from the list with a status other than MODE_OK. + * + * \param modeList pointer to a doubly-linked or circular list of modes. + * \param verbose determines whether the reason for mode invalidation is + * printed. + * + * This is not in xf86Modes.c, but would be part of the proposed new API. + */ +void +xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList, + Bool verbose) +{ + DisplayModePtr mode; + + for (mode = *modeList; mode != NULL;) { + DisplayModePtr next = mode->next, first = *modeList; + + if (mode->status != MODE_OK) { + if (verbose) { + char *type = ""; + if (mode->type & M_T_BUILTIN) + type = "built-in "; + else if (mode->type & M_T_DEFAULT) + type = "default "; + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Not using %smode \"%s\" (%s)\n", type, mode->name, + xf86ModeStatusToString(mode->status)); + } + xf86DeleteMode(modeList, mode); + } + + if (next == first) + break; + mode = next; + } +} + +/** + * Adds the new mode into the mode list, and returns the new list + * + * \param modes doubly-linked mode list. + */ +DisplayModePtr +xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new) +{ + if (modes == NULL) + return new; + + if (new) { + DisplayModePtr mode = modes; + + while (mode->next) + mode = mode->next; + + mode->next = new; + new->prev = mode; + } + + return modes; +} + +/** + * Build a mode list from a list of config file modes + */ +static DisplayModePtr +xf86GetConfigModes (XF86ConfModeLinePtr conf_mode) +{ + DisplayModePtr head = NULL, prev = NULL, mode; + + for (; conf_mode; conf_mode = (XF86ConfModeLinePtr) conf_mode->list.next) + { + mode = xcalloc(1, sizeof(DisplayModeRec)); + if (!mode) + continue; + mode->name = xstrdup(conf_mode->ml_identifier); + if (!mode->name) + { + xfree (mode); + continue; + } + mode->type = 0; + mode->Clock = conf_mode->ml_clock; + mode->HDisplay = conf_mode->ml_hdisplay; + mode->HSyncStart = conf_mode->ml_hsyncstart; + mode->HSyncEnd = conf_mode->ml_hsyncend; + mode->HTotal = conf_mode->ml_htotal; + mode->VDisplay = conf_mode->ml_vdisplay; + mode->VSyncStart = conf_mode->ml_vsyncstart; + mode->VSyncEnd = conf_mode->ml_vsyncend; + mode->VTotal = conf_mode->ml_vtotal; + mode->Flags = conf_mode->ml_flags; + mode->HSkew = conf_mode->ml_hskew; + mode->VScan = conf_mode->ml_vscan; + + mode->prev = prev; + mode->next = NULL; + if (prev) + prev->next = mode; + else + head = mode; + prev = mode; + } + return head; +} + +/** + * Build a mode list from a monitor configuration + */ +DisplayModePtr +xf86GetMonitorModes (ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor) +{ + DisplayModePtr modes = NULL; + XF86ConfModesLinkPtr modes_link; + + if (!conf_monitor) + return NULL; + + /* + * first we collect the mode lines from the UseModes directive + */ + for (modes_link = conf_monitor->mon_modes_sect_lst; + modes_link; + modes_link = modes_link->list.next) + { + /* If this modes link hasn't been resolved, go look it up now */ + if (!modes_link->ml_modes) + modes_link->ml_modes = xf86findModes (modes_link->ml_modes_str, + xf86configptr->conf_modes_lst); + if (modes_link->ml_modes) + modes = xf86ModesAdd (modes, + xf86GetConfigModes (modes_link->ml_modes->mon_modeline_lst)); + } + + return xf86ModesAdd (modes, + xf86GetConfigModes (conf_monitor->mon_modeline_lst)); +} + +/** + * Build a mode list containing all of the default modes + */ +DisplayModePtr +xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed) +{ + DisplayModePtr head = NULL, prev = NULL, mode; + int i; + + for (i = 0; xf86DefaultModes[i].name != NULL; i++) + { + DisplayModePtr defMode = &xf86DefaultModes[i]; + + if (!interlaceAllowed && (defMode->Flags & V_INTERLACE)) + continue; + if (!doubleScanAllowed && (defMode->Flags & V_DBLSCAN)) + continue; + + mode = xalloc(sizeof(DisplayModeRec)); + if (!mode) + continue; + memcpy(mode,&xf86DefaultModes[i],sizeof(DisplayModeRec)); + mode->name = xstrdup(xf86DefaultModes[i].name); + if (!mode->name) + { + xfree (mode); + continue; + } + mode->prev = prev; + mode->next = NULL; + if (prev) + prev->next = mode; + else + head = mode; + prev = mode; + } + return head; +} diff --git a/hw/xfree86/modes/xf86Modes.h b/hw/xfree86/modes/xf86Modes.h new file mode 100644 index 000000000..2bd4edeba --- /dev/null +++ b/hw/xfree86/modes/xf86Modes.h @@ -0,0 +1,98 @@ +/* + * Copyright © 2006 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Eric Anholt <eric@anholt.net> + * + */ + +#ifndef _XF86MODES_H_ +#define _XF86MODES_H_ + +#include <stddef.h> +#include <string.h> +#include <stdio.h> + +#include "xf86.h" +#include "xorgVersion.h" +#include "edid.h" +#include "xf86Parser.h" +#if XF86_MODES_RENAME +#include "xf86Rename.h" +#endif + +double xf86ModeHSync(DisplayModePtr mode); +double xf86ModeVRefresh(DisplayModePtr mode); + +int +xf86ModeWidth (DisplayModePtr mode, Rotation rotation); + +int +xf86ModeHeight (DisplayModePtr mode, Rotation rotation); + +DisplayModePtr xf86DuplicateMode(DisplayModePtr pMode); +DisplayModePtr xf86DuplicateModes(ScrnInfoPtr pScrn, + DisplayModePtr modeList); +void xf86SetModeDefaultName(DisplayModePtr mode); +void xf86SetModeCrtc(DisplayModePtr p, int adjustFlags); +Bool xf86ModesEqual(DisplayModePtr pMode1, DisplayModePtr pMode2); +void xf86PrintModeline(int scrnIndex,DisplayModePtr mode); +DisplayModePtr xf86ModesAdd(DisplayModePtr modes, DisplayModePtr new); + +DisplayModePtr xf86DDCGetModes(int scrnIndex, xf86MonPtr DDC); +DisplayModePtr xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, + Bool Reduced, Bool Interlaced); + +void +xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int flags); + +void +xf86ValidateModesClocks(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int *min, int *max, int n_ranges); + +void +xf86ValidateModesSize(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int maxX, int maxY, int maxPitch); + +void +xf86ValidateModesSync(ScrnInfoPtr pScrn, DisplayModePtr modeList, + MonPtr mon); + +void +xf86PruneInvalidModes(ScrnInfoPtr pScrn, DisplayModePtr *modeList, + Bool verbose); + +void +xf86ValidateModesFlags(ScrnInfoPtr pScrn, DisplayModePtr modeList, + int flags); + +void +xf86ValidateModesUserConfig(ScrnInfoPtr pScrn, DisplayModePtr modeList); + +DisplayModePtr +xf86GetMonitorModes (ScrnInfoPtr pScrn, XF86ConfMonitorPtr conf_monitor); + +DisplayModePtr +xf86GetDefaultModes (Bool interlaceAllowed, Bool doubleScanAllowed); + +#endif /* _XF86MODES_H_ */ diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c new file mode 100644 index 000000000..6f52ee2d9 --- /dev/null +++ b/hw/xfree86/modes/xf86RandR12.c @@ -0,0 +1,1088 @@ +/* $XdotOrg: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.3 2004/07/30 21:53:09 eich Exp $ */ +/* + * $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86RandR.c,v 1.7tsi Exp $ + * + * Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc. + * + * 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include "xf86.h" +#include "os.h" +#include "mibank.h" +#include "globals.h" +#include "xf86.h" +#include "xf86Priv.h" +#include "xf86DDC.h" +#include "mipointer.h" +#include "windowstr.h" +#include <randrstr.h> +#include <X11/extensions/render.h> + +#include "xf86Crtc.h" +#include "xf86RandR12.h" + +typedef struct _xf86RandR12Info { + int virtualX; + int virtualY; + int mmWidth; + int mmHeight; + int maxX; + int maxY; + Rotation rotation; /* current mode */ + Rotation supported_rotations; /* driver supported */ +} XF86RandRInfoRec, *XF86RandRInfoPtr; + +#ifdef RANDR_12_INTERFACE +static Bool xf86RandR12Init12 (ScreenPtr pScreen); +static Bool xf86RandR12CreateScreenResources12 (ScreenPtr pScreen); +#endif + +static int xf86RandR12Index; +static int xf86RandR12Generation; + +#define XF86RANDRINFO(p) \ + ((XF86RandRInfoPtr)(p)->devPrivates[xf86RandR12Index].ptr) + +static int +xf86RandR12ModeRefresh (DisplayModePtr mode) +{ + if (mode->VRefresh) + return (int) (mode->VRefresh + 0.5); + else + return (int) (mode->Clock * 1000.0 / mode->HTotal / mode->VTotal + 0.5); +} + +static Bool +xf86RandR12GetInfo (ScreenPtr pScreen, Rotation *rotations) +{ + RRScreenSizePtr pSize; + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + DisplayModePtr mode; + int refresh0 = 60; + int maxX = 0, maxY = 0; + + *rotations = randrp->supported_rotations; + + if (randrp->virtualX == -1 || randrp->virtualY == -1) + { + randrp->virtualX = scrp->virtualX; + randrp->virtualY = scrp->virtualY; + } + + /* Re-probe the outputs for new monitors or modes */ + xf86ProbeOutputModes (scrp, 0, 0); + xf86SetScrnInfoModes (scrp); + xf86DiDGAReInit (pScreen); + + for (mode = scrp->modes; ; mode = mode->next) + { + int refresh = xf86RandR12ModeRefresh (mode); + if (randrp->maxX == 0 || randrp->maxY == 0) + { + if (maxX < mode->HDisplay) + maxX = mode->HDisplay; + if (maxY < mode->VDisplay) + maxY = mode->VDisplay; + } + if (mode == scrp->modes) + refresh0 = refresh; + pSize = RRRegisterSize (pScreen, + mode->HDisplay, mode->VDisplay, + randrp->mmWidth, randrp->mmHeight); + if (!pSize) + return FALSE; + RRRegisterRate (pScreen, pSize, refresh); + + if (xf86ModesEqual(mode, scrp->currentMode) && + mode->HDisplay == scrp->virtualX && + mode->VDisplay == scrp->virtualY) + { + RRSetCurrentConfig (pScreen, randrp->rotation, refresh, pSize); + } + if (mode->next == scrp->modes) + break; + } + + if (randrp->maxX == 0 || randrp->maxY == 0) + { + randrp->maxX = maxX; + randrp->maxY = maxY; + } + + if (scrp->currentMode->HDisplay != randrp->virtualX || + scrp->currentMode->VDisplay != randrp->virtualY) + { + pSize = RRRegisterSize (pScreen, + randrp->virtualX, randrp->virtualY, + randrp->mmWidth, + randrp->mmHeight); + if (!pSize) + return FALSE; + RRRegisterRate (pScreen, pSize, refresh0); + if (scrp->virtualX == randrp->virtualX && + scrp->virtualY == randrp->virtualY) + { + RRSetCurrentConfig (pScreen, randrp->rotation, refresh0, pSize); + } + } + + return TRUE; +} + +static Bool +xf86RandR12SetMode (ScreenPtr pScreen, + DisplayModePtr mode, + Bool useVirtual, + int mmWidth, + int mmHeight) +{ + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + int oldWidth = pScreen->width; + int oldHeight = pScreen->height; + int oldmmWidth = pScreen->mmWidth; + int oldmmHeight = pScreen->mmHeight; + WindowPtr pRoot = WindowTable[pScreen->myNum]; + DisplayModePtr currentMode = NULL; + Bool ret = TRUE; + PixmapPtr pspix = NULL; + + if (pRoot) + (*scrp->EnableDisableFBAccess) (pScreen->myNum, FALSE); + if (useVirtual) + { + scrp->virtualX = randrp->virtualX; + scrp->virtualY = randrp->virtualY; + } + else + { + scrp->virtualX = mode->HDisplay; + scrp->virtualY = mode->VDisplay; + } + + 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; + } + if (scrp->currentMode == mode) { + /* Save current mode */ + currentMode = scrp->currentMode; + /* Reset, just so we ensure the drivers SwitchMode is called */ + scrp->currentMode = NULL; + } + /* + * We know that if the driver failed to SwitchMode to the rotated + * version, then it should revert back to it's prior mode. + */ + if (!xf86SwitchMode (pScreen, mode)) + { + ret = FALSE; + scrp->virtualX = pScreen->width = oldWidth; + scrp->virtualY = pScreen->height = oldHeight; + pScreen->mmWidth = oldmmWidth; + pScreen->mmHeight = oldmmHeight; + scrp->currentMode = currentMode; + } + /* + * Get the new Screen pixmap ptr as SwitchMode might have called + * ModifyPixmapHeader and xf86EnableDisableFBAccess will put it back... + * Unfortunately. + */ + pspix = (*pScreen->GetScreenPixmap) (pScreen); + if (pspix->devPrivate.ptr) + scrp->pixmapPrivate = pspix->devPrivate; + + /* + * 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; +} + +Bool +xf86RandR12SetConfig (ScreenPtr pScreen, + Rotation rotation, + int rate, + RRScreenSizePtr pSize) +{ + ScrnInfoPtr scrp = XF86SCRNINFO(pScreen); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + DisplayModePtr mode; + int px, py; + Bool useVirtual = FALSE; + int maxX = 0, maxY = 0; + Rotation oldRotation = randrp->rotation; + + randrp->rotation = rotation; + + if (randrp->virtualX == -1 || randrp->virtualY == -1) + { + randrp->virtualX = scrp->virtualX; + randrp->virtualY = scrp->virtualY; + } + + miPointerPosition (&px, &py); + for (mode = scrp->modes; ; mode = mode->next) + { + if (randrp->maxX == 0 || randrp->maxY == 0) + { + if (maxX < mode->HDisplay) + maxX = mode->HDisplay; + if (maxY < mode->VDisplay) + maxY = mode->VDisplay; + } + if (mode->HDisplay == pSize->width && + mode->VDisplay == pSize->height && + (rate == 0 || xf86RandR12ModeRefresh (mode) == rate)) + break; + if (mode->next == scrp->modes) + { + if (pSize->width == randrp->virtualX && + pSize->height == randrp->virtualY) + { + mode = scrp->modes; + useVirtual = TRUE; + break; + } + if (randrp->maxX == 0 || randrp->maxY == 0) + { + randrp->maxX = maxX; + randrp->maxY = maxY; + } + return FALSE; + } + } + + if (randrp->maxX == 0 || randrp->maxY == 0) + { + randrp->maxX = maxX; + randrp->maxY = maxY; + } + + if (!xf86RandR12SetMode (pScreen, mode, useVirtual, pSize->mmWidth, + pSize->mmHeight)) { + randrp->rotation = oldRotation; + return FALSE; + } + + /* + * 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); + + xf86SetViewport(pScreen, px, py); + + (*pScreen->SetCursorPosition) (pScreen, px, py, FALSE); + } + + return TRUE; +} + +static Bool +xf86RandR12ScreenSetSize (ScreenPtr pScreen, + CARD16 width, + CARD16 height, + CARD32 mmWidth, + CARD32 mmHeight) +{ + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + ScrnInfoPtr pScrn = XF86SCRNINFO(pScreen); + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + WindowPtr pRoot = WindowTable[pScreen->myNum]; + Bool ret = FALSE; + + if (randrp->virtualX == -1 || randrp->virtualY == -1) + { + randrp->virtualX = pScrn->virtualX; + randrp->virtualY = pScrn->virtualY; + } + if (pRoot) + (*pScrn->EnableDisableFBAccess) (pScreen->myNum, FALSE); + + /* Let the driver update virtualX and virtualY */ + if (!(*config->funcs->resize)(pScrn, width, height)) + goto finish; + + ret = TRUE; + + pScreen->width = width; + pScreen->height = height; + pScreen->mmWidth = mmWidth; + pScreen->mmHeight = mmHeight; + + xf86SetViewport (pScreen, pScreen->width-1, pScreen->height-1); + xf86SetViewport (pScreen, 0, 0); + +finish: + if (pRoot) + (*pScrn->EnableDisableFBAccess) (pScreen->myNum, TRUE); +#if RANDR_12_INTERFACE + if (WindowTable[pScreen->myNum] && ret) + RRScreenSizeNotify (pScreen); +#endif + return ret; +} + +Rotation +xf86RandR12GetRotation(ScreenPtr pScreen) +{ + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + + return randrp->rotation; +} + +Bool +xf86RandR12CreateScreenResources (ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + int c; + int width, height; + int mmWidth, mmHeight; +#ifdef PANORAMIX + /* XXX disable RandR when using Xinerama */ + if (!noPanoramiXExtension) + return TRUE; +#endif + + /* + * Compute size of screen + */ + width = 0; height = 0; + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + int crtc_width = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation); + int crtc_height = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation); + + if (crtc->enabled && crtc_width > width) + width = crtc_width; + if (crtc->enabled && crtc_height > height) + height = crtc_height; + } + + if (width && height) + { + /* + * Compute physical size of screen + */ + if (monitorResolution) + { + mmWidth = width * 25.4 / monitorResolution; + mmHeight = height * 25.4 / monitorResolution; + } + else + { + xf86OutputPtr output = config->output[config->compat_output]; + xf86CrtcPtr crtc = output->crtc; + + if (crtc && crtc->mode.HDisplay && + output->mm_width && output->mm_height) + { + /* + * If the output has a mode and a declared size, use that + * to scale the screen size + */ + DisplayModePtr mode = &crtc->mode; + mmWidth = output->mm_width * width / mode->HDisplay; + mmHeight = output->mm_height * height / mode->VDisplay; + } + else + { + /* + * Otherwise, just set the screen to 96dpi + */ + mmWidth = width * 25.4 / 96; + mmHeight = height * 25.4 / 96; + } + } + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Setting screen physical size to %d x %d\n", + mmWidth, mmHeight); + xf86RandR12ScreenSetSize (pScreen, + width, + height, + mmWidth, + mmHeight); + } + + if (randrp->virtualX == -1 || randrp->virtualY == -1) + { + randrp->virtualX = pScrn->virtualX; + randrp->virtualY = pScrn->virtualY; + } + xf86CrtcSetScreenSubpixelOrder (pScreen); +#if RANDR_12_INTERFACE + if (xf86RandR12CreateScreenResources12 (pScreen)) + return TRUE; +#endif + return TRUE; +} + + +Bool +xf86RandR12Init (ScreenPtr pScreen) +{ + rrScrPrivPtr rp; + XF86RandRInfoPtr randrp; + +#ifdef PANORAMIX + /* XXX disable RandR when using Xinerama */ + if (!noPanoramiXExtension) + return TRUE; +#endif + if (xf86RandR12Generation != serverGeneration) + { + xf86RandR12Index = AllocateScreenPrivateIndex(); + xf86RandR12Generation = serverGeneration; + } + + randrp = xalloc (sizeof (XF86RandRInfoRec)); + if (!randrp) + return FALSE; + + if (!RRScreenInit(pScreen)) + { + xfree (randrp); + return FALSE; + } + rp = rrGetScrPriv(pScreen); + rp->rrGetInfo = xf86RandR12GetInfo; + rp->rrSetConfig = xf86RandR12SetConfig; + + randrp->virtualX = -1; + randrp->virtualY = -1; + randrp->mmWidth = pScreen->mmWidth; + randrp->mmHeight = pScreen->mmHeight; + + randrp->rotation = RR_Rotate_0; /* initial rotated mode */ + + randrp->supported_rotations = RR_Rotate_0; + + randrp->maxX = randrp->maxY = 0; + + pScreen->devPrivates[xf86RandR12Index].ptr = randrp; + +#if RANDR_12_INTERFACE + if (!xf86RandR12Init12 (pScreen)) + return FALSE; +#endif + return TRUE; +} + +void +xf86RandR12SetRotations (ScreenPtr pScreen, Rotation rotations) +{ + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); +#if RANDR_12_INTERFACE + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + int c; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + + for (c = 0; c < config->num_crtc; c++) { + xf86CrtcPtr crtc = config->crtc[c]; + + RRCrtcSetRotations (crtc->randr_crtc, rotations); + } +#endif + randrp->supported_rotations = rotations; +} + +void +xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, int *x, int *y) +{ + ScreenPtr pScreen = screenInfo.screens[pScrn->scrnIndex]; + + if (xf86RandR12Generation != serverGeneration || + XF86RANDRINFO(pScreen)->virtualX == -1) + { + *x = pScrn->virtualX; + *y = pScrn->virtualY; + } else { + XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen); + + *x = randrp->virtualX; + *y = randrp->virtualY; + } +} + +#if RANDR_12_INTERFACE + +#define FLAG_BITS (RR_HSyncPositive | \ + RR_HSyncNegative | \ + RR_VSyncPositive | \ + RR_VSyncNegative | \ + RR_Interlace | \ + RR_DoubleScan | \ + RR_CSync | \ + RR_CSyncPositive | \ + RR_CSyncNegative | \ + RR_HSkewPresent | \ + RR_BCast | \ + RR_PixelMultiplex | \ + RR_DoubleClock | \ + RR_ClockDivideBy2) + +static Bool +xf86RandRModeMatches (RRModePtr randr_mode, + DisplayModePtr mode) +{ +#if 0 + if (match_name) + { + /* check for same name */ + int len = strlen (mode->name); + if (randr_mode->mode.nameLength != len) return FALSE; + if (memcmp (randr_mode->name, mode->name, len) != 0) return FALSE; + } +#endif + + /* check for same timings */ + if (randr_mode->mode.dotClock / 1000 != mode->Clock) return FALSE; + if (randr_mode->mode.width != mode->HDisplay) return FALSE; + if (randr_mode->mode.hSyncStart != mode->HSyncStart) return FALSE; + if (randr_mode->mode.hSyncEnd != mode->HSyncEnd) return FALSE; + if (randr_mode->mode.hTotal != mode->HTotal) return FALSE; + if (randr_mode->mode.hSkew != mode->HSkew) return FALSE; + if (randr_mode->mode.height != mode->VDisplay) return FALSE; + if (randr_mode->mode.vSyncStart != mode->VSyncStart) return FALSE; + if (randr_mode->mode.vSyncEnd != mode->VSyncEnd) return FALSE; + if (randr_mode->mode.vTotal != mode->VTotal) return FALSE; + + /* check for same flags (using only the XF86 valid flag bits) */ + if ((randr_mode->mode.modeFlags & FLAG_BITS) != (mode->Flags & FLAG_BITS)) + return FALSE; + + /* everything matches */ + return TRUE; +} + +static Bool +xf86RandR12CrtcNotify (RRCrtcPtr randr_crtc) +{ + ScreenPtr pScreen = randr_crtc->pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + RRModePtr randr_mode = NULL; + int x; + int y; + Rotation rotation; + int numOutputs; + RROutputPtr *randr_outputs; + RROutputPtr randr_output; + xf86CrtcPtr crtc = randr_crtc->devPrivate; + xf86OutputPtr output; + int i, j; + DisplayModePtr mode = &crtc->mode; + Bool ret; + + randr_outputs = ALLOCATE_LOCAL(config->num_output * sizeof (RROutputPtr)); + if (!randr_outputs) + return FALSE; + x = crtc->x; + y = crtc->y; + rotation = crtc->rotation; + numOutputs = 0; + randr_mode = NULL; + for (i = 0; i < config->num_output; i++) + { + output = config->output[i]; + if (output->crtc == crtc) + { + randr_output = output->randr_output; + randr_outputs[numOutputs++] = randr_output; + /* + * We make copies of modes, so pointer equality + * isn't sufficient + */ + for (j = 0; j < randr_output->numModes + randr_output->numUserModes; j++) + { + RRModePtr m = (j < randr_output->numModes ? + randr_output->modes[j] : + randr_output->userModes[j-randr_output->numModes]); + + if (xf86RandRModeMatches (m, mode)) + { + randr_mode = m; + break; + } + } + } + } + ret = RRCrtcNotify (randr_crtc, randr_mode, x, y, + rotation, numOutputs, randr_outputs); + DEALLOCATE_LOCAL(randr_outputs); + return ret; +} + +/* + * Convert a RandR mode to a DisplayMode + */ +static void +xf86RandRModeConvert (ScrnInfoPtr scrn, + RRModePtr randr_mode, + DisplayModePtr mode) +{ + mode->prev = NULL; + mode->next = NULL; + mode->name = NULL; + mode->status = MODE_OK; + mode->type = 0; + + mode->Clock = randr_mode->mode.dotClock / 1000; + + mode->HDisplay = randr_mode->mode.width; + mode->HSyncStart = randr_mode->mode.hSyncStart; + mode->HSyncEnd = randr_mode->mode.hSyncEnd; + mode->HTotal = randr_mode->mode.hTotal; + mode->HSkew = randr_mode->mode.hSkew; + + mode->VDisplay = randr_mode->mode.height; + mode->VSyncStart = randr_mode->mode.vSyncStart; + mode->VSyncEnd = randr_mode->mode.vSyncEnd; + mode->VTotal = randr_mode->mode.vTotal; + mode->VScan = 0; + + mode->Flags = randr_mode->mode.modeFlags & FLAG_BITS; + + xf86SetModeCrtc (mode, scrn->adjustFlags); +} + +static Bool +xf86RandR12CrtcSet (ScreenPtr pScreen, + RRCrtcPtr randr_crtc, + RRModePtr randr_mode, + int x, + int y, + Rotation rotation, + int num_randr_outputs, + RROutputPtr *randr_outputs) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + xf86CrtcPtr crtc = randr_crtc->devPrivate; + Bool changed = FALSE; + int o, ro; + xf86CrtcPtr *save_crtcs; + Bool save_enabled = crtc->enabled; + + save_crtcs = ALLOCATE_LOCAL(config->num_crtc * sizeof (xf86CrtcPtr)); + if ((randr_mode != NULL) != crtc->enabled) + changed = TRUE; + else if (randr_mode && !xf86RandRModeMatches (randr_mode, &crtc->mode)) + changed = TRUE; + + if (rotation != crtc->rotation) + changed = TRUE; + + if (x != crtc->x || y != crtc->y) + changed = TRUE; + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + xf86CrtcPtr new_crtc; + + save_crtcs[o] = output->crtc; + + if (output->crtc == crtc) + new_crtc = NULL; + else + new_crtc = output->crtc; + for (ro = 0; ro < num_randr_outputs; ro++) + if (output->randr_output == randr_outputs[ro]) + { + new_crtc = crtc; + break; + } + if (new_crtc != output->crtc) + { + changed = TRUE; + output->crtc = new_crtc; + } + } + /* XXX need device-independent mode setting code through an API */ + if (changed) + { + crtc->enabled = randr_mode != NULL; + + if (randr_mode) + { + DisplayModeRec mode; + + xf86RandRModeConvert (pScrn, randr_mode, &mode); + if (!xf86CrtcSetMode (crtc, &mode, rotation, x, y)) + { + crtc->enabled = save_enabled; + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + output->crtc = save_crtcs[o]; + } + DEALLOCATE_LOCAL(save_crtcs); + return FALSE; + } + /* + * Save the last successful setting for EnterVT + */ + crtc->desiredMode = mode; + crtc->desiredRotation = rotation; + crtc->desiredX = x; + crtc->desiredY = y; + } + xf86DisableUnusedFunctions (pScrn); + } + DEALLOCATE_LOCAL(save_crtcs); + return xf86RandR12CrtcNotify (randr_crtc); +} + +static Bool +xf86RandR12CrtcSetGamma (ScreenPtr pScreen, + RRCrtcPtr randr_crtc) +{ + xf86CrtcPtr crtc = randr_crtc->devPrivate; + + if (crtc->funcs->gamma_set == NULL) + return FALSE; + + crtc->funcs->gamma_set(crtc, randr_crtc->gammaRed, randr_crtc->gammaGreen, + randr_crtc->gammaBlue, randr_crtc->gammaSize); + + return TRUE; +} + +static Bool +xf86RandR12OutputSetProperty (ScreenPtr pScreen, + RROutputPtr randr_output, + Atom property, + RRPropertyValuePtr value) +{ + xf86OutputPtr output = randr_output->devPrivate; + + /* If we don't have any property handler, then we don't care what the + * user is setting properties to. + */ + if (output->funcs->set_property == NULL) + return TRUE; + + return output->funcs->set_property(output, property, value); +} + +static Bool +xf86RandR12OutputValidateMode (ScreenPtr pScreen, + RROutputPtr randr_output, + RRModePtr randr_mode) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86OutputPtr output = randr_output->devPrivate; + DisplayModeRec mode; + + xf86RandRModeConvert (pScrn, randr_mode, &mode); + if (output->funcs->mode_valid (output, &mode) != MODE_OK) + return FALSE; + return TRUE; +} + +static void +xf86RandR12ModeDestroy (ScreenPtr pScreen, RRModePtr randr_mode) +{ +} + +/** + * Given a list of xf86 modes and a RandR Output object, construct + * RandR modes and assign them to the output + */ +static Bool +xf86RROutputSetModes (RROutputPtr randr_output, DisplayModePtr modes) +{ + DisplayModePtr mode; + RRModePtr *rrmodes = NULL; + int nmode = 0; + int npreferred = 0; + Bool ret = TRUE; + int pref; + + for (mode = modes; mode; mode = mode->next) + nmode++; + + if (nmode) { + rrmodes = xalloc (nmode * sizeof (RRModePtr)); + + if (!rrmodes) + return FALSE; + nmode = 0; + + for (pref = 1; pref >= 0; pref--) { + for (mode = modes; mode; mode = mode->next) { + if ((pref != 0) == ((mode->type & M_T_PREFERRED) != 0)) { + xRRModeInfo modeInfo; + RRModePtr rrmode; + + modeInfo.nameLength = strlen (mode->name); + modeInfo.width = mode->HDisplay; + modeInfo.dotClock = mode->Clock * 1000; + modeInfo.hSyncStart = mode->HSyncStart; + modeInfo.hSyncEnd = mode->HSyncEnd; + modeInfo.hTotal = mode->HTotal; + modeInfo.hSkew = mode->HSkew; + + modeInfo.height = mode->VDisplay; + modeInfo.vSyncStart = mode->VSyncStart; + modeInfo.vSyncEnd = mode->VSyncEnd; + modeInfo.vTotal = mode->VTotal; + modeInfo.modeFlags = mode->Flags; + + rrmode = RRModeGet (&modeInfo, mode->name); + if (rrmode) { + rrmodes[nmode++] = rrmode; + npreferred += pref; + } + } + } + } + } + + ret = RROutputSetModes (randr_output, rrmodes, nmode, npreferred); + xfree (rrmodes); + return ret; +} + +/* + * Mirror the current mode configuration to RandR + */ +static Bool +xf86RandR12SetInfo12 (ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + RROutputPtr *clones; + RRCrtcPtr *crtcs; + int ncrtc; + int o, c, l; + RRCrtcPtr randr_crtc; + int nclone; + + clones = ALLOCATE_LOCAL(config->num_output * sizeof (RROutputPtr)); + crtcs = ALLOCATE_LOCAL (config->num_crtc * sizeof (RRCrtcPtr)); + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + ncrtc = 0; + for (c = 0; c < config->num_crtc; c++) + if (output->possible_crtcs & (1 << c)) + crtcs[ncrtc++] = config->crtc[c]->randr_crtc; + + if (output->crtc) + randr_crtc = output->crtc->randr_crtc; + else + randr_crtc = NULL; + + if (!RROutputSetCrtcs (output->randr_output, crtcs, ncrtc)) + { + DEALLOCATE_LOCAL (crtcs); + DEALLOCATE_LOCAL (clones); + return FALSE; + } + + RROutputSetCrtc (output->randr_output, randr_crtc); + RROutputSetPhysicalSize(output->randr_output, + output->mm_width, + output->mm_height); + xf86RROutputSetModes (output->randr_output, output->probed_modes); + + switch (output->status) { + case XF86OutputStatusConnected: + RROutputSetConnection (output->randr_output, RR_Connected); + break; + case XF86OutputStatusDisconnected: + RROutputSetConnection (output->randr_output, RR_Disconnected); + break; + case XF86OutputStatusUnknown: + RROutputSetConnection (output->randr_output, RR_UnknownConnection); + break; + } + + RROutputSetSubpixelOrder (output->randr_output, output->subpixel_order); + + /* + * Valid clones + */ + nclone = 0; + for (l = 0; l < config->num_output; l++) + { + xf86OutputPtr clone = config->output[l]; + + if (l != o && (output->possible_clones & (1 << l))) + clones[nclone++] = clone->randr_output; + } + if (!RROutputSetClones (output->randr_output, clones, nclone)) + { + DEALLOCATE_LOCAL (crtcs); + DEALLOCATE_LOCAL (clones); + return FALSE; + } + } + DEALLOCATE_LOCAL (crtcs); + DEALLOCATE_LOCAL (clones); + return TRUE; +} + + + +/* + * Query the hardware for the current state, then mirror + * that to RandR + */ +static Bool +xf86RandR12GetInfo12 (ScreenPtr pScreen, Rotation *rotations) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + + xf86ProbeOutputModes (pScrn, 0, 0); + xf86SetScrnInfoModes (pScrn); + xf86DiDGAReInit (pScreen); + return xf86RandR12SetInfo12 (pScreen); +} + +static Bool +xf86RandR12CreateObjects12 (ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int c; + int o; + + if (!RRInit ()) + return FALSE; + + /* + * Configure crtcs + */ + for (c = 0; c < config->num_crtc; c++) + { + xf86CrtcPtr crtc = config->crtc[c]; + + crtc->randr_crtc = RRCrtcCreate (pScreen, crtc); + RRCrtcGammaSetSize (crtc->randr_crtc, 256); + } + /* + * Configure outputs + */ + for (o = 0; o < config->num_output; o++) + { + xf86OutputPtr output = config->output[o]; + + output->randr_output = RROutputCreate (pScreen, output->name, + strlen (output->name), + output); + + if (output->funcs->create_resources != NULL) + output->funcs->create_resources(output); + RRPostPendingProperties (output->randr_output); + } + return TRUE; +} + +static Bool +xf86RandR12CreateScreenResources12 (ScreenPtr pScreen) +{ + int c; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + + for (c = 0; c < config->num_crtc; c++) + xf86RandR12CrtcNotify (config->crtc[c]->randr_crtc); + + + RRScreenSetSizeRange (pScreen, config->minWidth, config->minHeight, + config->maxWidth, config->maxHeight); + return TRUE; +} + +static void +xf86RandR12PointerMoved (int scrnIndex, int x, int y) +{ +} + +static Bool +xf86RandR12Init12 (ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + rrScrPrivPtr rp = rrGetScrPriv(pScreen); + + rp->rrGetInfo = xf86RandR12GetInfo12; + rp->rrScreenSetSize = xf86RandR12ScreenSetSize; + rp->rrCrtcSet = xf86RandR12CrtcSet; + rp->rrCrtcSetGamma = xf86RandR12CrtcSetGamma; + rp->rrOutputSetProperty = xf86RandR12OutputSetProperty; + rp->rrOutputValidateMode = xf86RandR12OutputValidateMode; + rp->rrModeDestroy = xf86RandR12ModeDestroy; + rp->rrSetConfig = NULL; + pScrn->PointerMoved = xf86RandR12PointerMoved; + if (!xf86RandR12CreateObjects12 (pScreen)) + return FALSE; + + /* + * Configure output modes + */ + if (!xf86RandR12SetInfo12 (pScreen)) + return FALSE; + return TRUE; +} + +#endif + +Bool +xf86RandR12PreInit (ScrnInfoPtr pScrn) +{ + return TRUE; +} diff --git a/hw/xfree86/modes/xf86RandR12.h b/hw/xfree86/modes/xf86RandR12.h new file mode 100644 index 000000000..8a4668b46 --- /dev/null +++ b/hw/xfree86/modes/xf86RandR12.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef _XF86_RANDR_H_ +#define _XF86_RANDR_H_ +#include <randrstr.h> +#include <X11/extensions/render.h> + +Bool xf86RandR12CreateScreenResources (ScreenPtr pScreen); +Bool xf86RandR12Init(ScreenPtr pScreen); +void xf86RandR12SetRotations (ScreenPtr pScreen, Rotation rotation); +Bool xf86RandR12SetConfig(ScreenPtr pScreen, Rotation rotation, int rate, + RRScreenSizePtr pSize); +Rotation xf86RandR12GetRotation(ScreenPtr pScreen); +void xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, int *x, int *y); +Bool xf86RandR12PreInit (ScrnInfoPtr pScrn); + +#endif /* _XF86_RANDR_H_ */ diff --git a/hw/xfree86/modes/xf86Rename.h b/hw/xfree86/modes/xf86Rename.h new file mode 100644 index 000000000..9dcfef5da --- /dev/null +++ b/hw/xfree86/modes/xf86Rename.h @@ -0,0 +1,84 @@ +/* + * 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. + */ + +#ifndef _XF86RENAME_H_ +#define _XF86RENAME_H_ + +#include "local_xf86Rename.h" + +#define xf86CrtcConfigInit XF86NAME(xf86CrtcConfigInit) +#define xf86CrtcConfigPrivateIndex XF86NAME(xf86CrtcConfigPrivateIndex) +#define xf86CrtcCreate XF86NAME(xf86CrtcCreate) +#define xf86CrtcDestroy XF86NAME(xf86CrtcDestroy) +#define xf86CrtcInUse XF86NAME(xf86CrtcInUse) +#define xf86CrtcRotate XF86NAME(xf86CrtcRotate) +#define xf86CrtcScreenInit XF86NAME(xf86CrtcScreenInit) +#define xf86CrtcSetMode XF86NAME(xf86CrtcSetMode) +#define xf86CrtcSetSizeRange XF86NAME(xf86CrtcSetSizeRange) +#define xf86CVTMode XF86NAME(xf86CVTMode) +#define xf86DisableUnusedFunctions XF86NAME(xf86DisableUnusedFunctions) +#define xf86DPMSSet XF86NAME(xf86DPMSSet) +#define xf86DuplicateMode XF86NAME(xf86DuplicateMode) +#define xf86DuplicateModes XF86NAME(xf86DuplicateModes) +#define xf86GetDefaultModes XF86NAME(xf86GetDefaultModes) +#define xf86GetMonitorModes XF86NAME(xf86GetMonitorModes) +#define xf86InitialConfiguration XF86NAME(xf86InitialConfiguration) +#define xf86ModeHSync XF86NAME(xf86ModeHSync) +#define xf86ModesAdd XF86NAME(xf86ModesAdd) +#define xf86ModesEqual XF86NAME(xf86ModesEqual) +#define xf86ModeVRefresh XF86NAME(xf86ModeVRefresh) +#define xf86OutputCreate XF86NAME(xf86OutputCreate) +#define xf86OutputDestroy XF86NAME(xf86OutputDestroy) +#define xf86OutputGetEDID XF86NAME(xf86OutputGetEDID) +#define xf86OutputGetEDIDModes XF86NAME(xf86OutputGetEDIDModes) +#define xf86OutputRename XF86NAME(xf86OutputRename) +#define xf86OutputSetEDID XF86NAME(xf86OutputSetEDID) +#define xf86PrintModeline XF86NAME(xf86PrintModeline) +#define xf86ProbeOutputModes XF86NAME(xf86ProbeOutputModes) +#define xf86PruneInvalidModes XF86NAME(xf86PruneInvalidModes) +#define xf86SetModeCrtc XF86NAME(xf86SetModeCrtc) +#define xf86SetModeDefaultName XF86NAME(xf86SetModeDefaultName) +#define xf86SetScrnInfoModes XF86NAME(xf86SetScrnInfoModes) +#define xf86ValidateModesClocks XF86NAME(xf86ValidateModesClocks) +#define xf86ValidateModesFlags XF86NAME(xf86ValidateModesFlags) +#define xf86ValidateModesSize XF86NAME(xf86ValidateModesSize) +#define xf86ValidateModesSync XF86NAME(xf86ValidateModesSync) +#define xf86ValidateModesUserConfig XF86NAME(xf86ValidateModesUserConfig) +#define xf86DiDGAInit XF86NAME(xf86DiDGAInit) +#define xf86DiDGAReInit XF86NAME(xf86DiDGAReInit) +#define xf86DDCGetModes XF86NAME(xf86DDCGetModes) +#define xf86RandR12CreateScreenResources XF86NAME(xf86RandR12CreateScreenResources) +#define xf86RandR12GetOriginalVirtualSize XF86NAME(xf86RandR12GetOriginalVirtualSize) +#define xf86RandR12GetRotation XF86NAME(xf86RandR12GetRotation) +#define xf86RandR12Init XF86NAME(xf86RandR12Init) +#define xf86RandR12PreInit XF86NAME(xf86RandR12PreInit) +#define xf86RandR12SetConfig XF86NAME(xf86RandR12SetConfig) +#define xf86RandR12SetRotations XF86NAME(xf86RandR12SetRotations) +#define xf86SaveScreen XF86NAME(xf86SaveScreen) +#define xf86CrtcSetScreenSubpixelOrder XF86NAME(xf86CrtcSetScreenSubpixelOrder) +#define xf86ModeWidth XF86NAME(xf86ModeWidth) +#define xf86ModeHeight XF86NAME(xf86ModeHeight) +#define xf86OutputFindClosestMode XF86NAME(xf86OutputFindClosestMode) +#define xf86SetSingleMode XF86NAME(xf86SetSingleMode) +#define xf86SetDesiredModes XF86NAME(xf86SetDesiredModes) + +#endif /* _XF86RENAME_H_ */ diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c new file mode 100644 index 000000000..e8fafd073 --- /dev/null +++ b/hw/xfree86/modes/xf86Rotate.c @@ -0,0 +1,464 @@ +/* + * 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. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include <stddef.h> +#include <string.h> +#include <stdio.h> + +#include "xf86.h" +#include "xf86DDC.h" +#include "fb.h" +#include "windowstr.h" +#include "xf86Crtc.h" +#include "xf86Modes.h" +#include "xf86RandR12.h" +#include "X11/extensions/render.h" +#define DPMS_SERVER +#include "X11/extensions/dpms.h" +#include "X11/Xatom.h" + +/* borrowed from composite extension, move to Render and publish? */ + +static VisualPtr +compGetWindowVisual (WindowPtr pWin) +{ + ScreenPtr pScreen = pWin->drawable.pScreen; + VisualID vid = wVisual (pWin); + int i; + + for (i = 0; i < pScreen->numVisuals; i++) + if (pScreen->visuals[i].vid == vid) + return &pScreen->visuals[i]; + return 0; +} + +static PictFormatPtr +compWindowFormat (WindowPtr pWin) +{ + ScreenPtr pScreen = pWin->drawable.pScreen; + + return PictureMatchVisual (pScreen, pWin->drawable.depth, + compGetWindowVisual (pWin)); +} + +static void +xf86TranslateBox (BoxPtr b, int dx, int dy) +{ + b->x1 += dx; + b->y1 += dy; + b->x2 += dx; + b->y2 += dy; +} + +static void +xf86TransformBox (BoxPtr dst, BoxPtr src, Rotation rotation, + int xoff, int yoff, + int dest_width, int dest_height) +{ + BoxRec stmp = *src; + + xf86TranslateBox (&stmp, -xoff, -yoff); + switch (rotation & 0xf) { + default: + case RR_Rotate_0: + *dst = stmp; + break; + case RR_Rotate_90: + dst->x1 = stmp.y1; + dst->y1 = dest_height - stmp.x2; + dst->x2 = stmp.y2; + dst->y2 = dest_height - stmp.x1; + break; + case RR_Rotate_180: + dst->x1 = dest_width - stmp.x2; + dst->y1 = dest_height - stmp.y2; + dst->x2 = dest_width - stmp.x1; + dst->y2 = dest_height - stmp.y1; + break; + case RR_Rotate_270: + dst->x1 = dest_width - stmp.y2; + dst->y1 = stmp.x1; + dst->y2 = stmp.x2; + dst->x2 = dest_width - stmp.y1; + break; + } + if (rotation & RR_Reflect_X) { + int x1 = dst->x1; + dst->x1 = dest_width - dst->x2; + dst->x2 = dest_width - x1; + } + if (rotation & RR_Reflect_Y) { + int y1 = dst->y1; + dst->y1 = dest_height - dst->y2; + dst->y2 = dest_height - y1; + } +} + +static void +xf86RotateCrtcRedisplay (xf86CrtcPtr crtc, RegionPtr region) +{ + ScrnInfoPtr scrn = crtc->scrn; + ScreenPtr screen = scrn->pScreen; + WindowPtr root = WindowTable[screen->myNum]; + PixmapPtr dst_pixmap = crtc->rotatedPixmap; + PictFormatPtr format = compWindowFormat (WindowTable[screen->myNum]); + int error; + PicturePtr src, dst; + PictTransform transform; + int n = REGION_NUM_RECTS(region); + BoxPtr b = REGION_RECTS(region); + XID include_inferiors = IncludeInferiors; + + src = CreatePicture (None, + &root->drawable, + format, + CPSubwindowMode, + &include_inferiors, + serverClient, + &error); + if (!src) + return; + + dst = CreatePicture (None, + &dst_pixmap->drawable, + format, + 0L, + NULL, + serverClient, + &error); + if (!dst) + return; + + memset (&transform, '\0', sizeof (transform)); + transform.matrix[2][2] = IntToxFixed(1); + transform.matrix[0][2] = IntToxFixed(crtc->x); + transform.matrix[1][2] = IntToxFixed(crtc->y); + switch (crtc->rotation & 0xf) { + default: + case RR_Rotate_0: + transform.matrix[0][0] = IntToxFixed(1); + transform.matrix[1][1] = IntToxFixed(1); + break; + case RR_Rotate_90: + transform.matrix[0][1] = IntToxFixed(-1); + transform.matrix[1][0] = IntToxFixed(1); + transform.matrix[0][2] += IntToxFixed(crtc->mode.VDisplay); + break; + case RR_Rotate_180: + transform.matrix[0][0] = IntToxFixed(-1); + transform.matrix[1][1] = IntToxFixed(-1); + transform.matrix[0][2] += IntToxFixed(crtc->mode.HDisplay); + transform.matrix[1][2] += IntToxFixed(crtc->mode.VDisplay); + break; + case RR_Rotate_270: + transform.matrix[0][1] = IntToxFixed(1); + transform.matrix[1][0] = IntToxFixed(-1); + transform.matrix[1][2] += IntToxFixed(crtc->mode.HDisplay); + break; + } + + /* handle reflection */ + if (crtc->rotation & RR_Reflect_X) + { + /* XXX figure this out */ + } + if (crtc->rotation & RR_Reflect_Y) + { + /* XXX figure this out too */ + } + + error = SetPictureTransform (src, &transform); + if (error) + return; + + while (n--) + { + BoxRec dst_box; + + xf86TransformBox (&dst_box, b, crtc->rotation, + crtc->x, crtc->y, + crtc->mode.HDisplay, crtc->mode.VDisplay); + CompositePicture (PictOpSrc, + src, NULL, dst, + dst_box.x1, dst_box.y1, 0, 0, dst_box.x1, dst_box.y1, + dst_box.x2 - dst_box.x1, + dst_box.y2 - dst_box.y1); + b++; + } + FreePicture (src, None); + FreePicture (dst, None); +} + +static void +xf86CrtcDamageShadow (xf86CrtcPtr crtc) +{ + ScrnInfoPtr pScrn = crtc->scrn; + BoxRec damage_box; + RegionRec damage_region; + ScreenPtr pScreen = pScrn->pScreen; + + damage_box.x1 = crtc->x; + damage_box.x2 = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation); + damage_box.y1 = crtc->y; + damage_box.y2 = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation); + REGION_INIT (pScreen, &damage_region, &damage_box, 1); + DamageDamageRegion (&(*pScreen->GetScreenPixmap)(pScreen)->drawable, + &damage_region); + REGION_UNINIT (pScreen, &damage_region); +} + +static void +xf86RotatePrepare (ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->rotatedData && !crtc->rotatedPixmap) + { + crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc, + crtc->rotatedData, + crtc->mode.HDisplay, + crtc->mode.VDisplay); + if (!xf86_config->rotation_damage_registered) + { + /* Hook damage to screen pixmap */ + DamageRegister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable, + xf86_config->rotation_damage); + xf86_config->rotation_damage_registered = TRUE; + } + + xf86CrtcDamageShadow (crtc); + } + } +} + +static void +xf86RotateRedisplay(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + DamagePtr damage = xf86_config->rotation_damage; + RegionPtr region; + + if (!damage) + return; + xf86RotatePrepare (pScreen); + region = DamageRegion(damage); + if (REGION_NOTEMPTY(pScreen, region)) + { + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) + { + xf86CrtcPtr crtc = xf86_config->crtc[c]; + + if (crtc->rotation != RR_Rotate_0) + { + BoxRec box; + RegionRec crtc_damage; + + /* compute portion of damage that overlaps crtc */ + box.x1 = crtc->x; + box.x2 = crtc->x + xf86ModeWidth (&crtc->mode, crtc->rotation); + box.y1 = crtc->y; + box.y2 = crtc->y + xf86ModeHeight (&crtc->mode, crtc->rotation); + REGION_INIT(pScreen, &crtc_damage, &box, 1); + REGION_INTERSECT (pScreen, &crtc_damage, &crtc_damage, region); + + /* update damaged region */ + if (REGION_NOTEMPTY(pScreen, &crtc_damage)) + xf86RotateCrtcRedisplay (crtc, &crtc_damage); + + REGION_UNINIT (pScreen, &crtc_damage); + } + } + DamageEmpty(damage); + } +} + +static void +xf86RotateBlockHandler(pointer data, OSTimePtr pTimeout, pointer pRead) +{ + ScreenPtr pScreen = (ScreenPtr) data; + + xf86RotateRedisplay(pScreen); +} + +static void +xf86RotateWakeupHandler(pointer data, int i, pointer LastSelectMask) +{ +} + +static void +xf86RotateDestroy (xf86CrtcPtr crtc) +{ + ScrnInfoPtr pScrn = crtc->scrn; + ScreenPtr pScreen = pScrn->pScreen; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + int c; + + /* Free memory from rotation */ + if (crtc->rotatedPixmap || crtc->rotatedData) + { + crtc->funcs->shadow_destroy (crtc, crtc->rotatedPixmap, crtc->rotatedData); + crtc->rotatedPixmap = NULL; + crtc->rotatedData = NULL; + } + + for (c = 0; c < xf86_config->num_crtc; c++) + if (crtc->rotatedPixmap || crtc->rotatedData) + return; + + /* + * Clean up damage structures when no crtcs are rotated + */ + if (xf86_config->rotation_damage) + { + /* Free damage structure */ + if (xf86_config->rotation_damage_registered) + { + DamageUnregister (&(*pScreen->GetScreenPixmap)(pScreen)->drawable, + xf86_config->rotation_damage); + xf86_config->rotation_damage_registered = FALSE; + } + DamageDestroy (xf86_config->rotation_damage); + xf86_config->rotation_damage = NULL; + /* Free block/wakeup handler */ + RemoveBlockAndWakeupHandlers (xf86RotateBlockHandler, + xf86RotateWakeupHandler, + (pointer) pScreen); + } +} + +void +xf86RotateCloseScreen (ScreenPtr screen) +{ + ScrnInfoPtr scrn = xf86Screens[screen->myNum]; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn); + int c; + + for (c = 0; c < xf86_config->num_crtc; c++) + xf86RotateDestroy (xf86_config->crtc[c]); +} + +Bool +xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation) +{ + ScrnInfoPtr pScrn = crtc->scrn; + xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn); + ScreenPtr pScreen = pScrn->pScreen; + + if (rotation == RR_Rotate_0) + { + xf86RotateDestroy (crtc); + } + else + { + /* + * these are the size of the shadow pixmap, which + * matches the mode, not the pre-rotated copy in the + * frame buffer + */ + int width = mode->HDisplay; + int height = mode->VDisplay; + void *shadowData = crtc->rotatedData; + PixmapPtr shadow = crtc->rotatedPixmap; + int old_width = shadow ? shadow->drawable.width : 0; + int old_height = shadow ? shadow->drawable.height : 0; + + /* Allocate memory for rotation */ + if (old_width != width || old_height != height) + { + if (shadow || shadowData) + { + crtc->funcs->shadow_destroy (crtc, shadow, shadowData); + crtc->rotatedPixmap = NULL; + crtc->rotatedData = NULL; + } + shadowData = crtc->funcs->shadow_allocate (crtc, width, height); + if (!shadowData) + goto bail1; + crtc->rotatedData = shadowData; + /* shadow will be damaged in xf86RotatePrepare */ + } + else + { + /* mark shadowed area as damaged so it will be repainted */ + xf86CrtcDamageShadow (crtc); + } + + if (!xf86_config->rotation_damage) + { + /* Create damage structure */ + xf86_config->rotation_damage = DamageCreate (NULL, NULL, + DamageReportNone, + TRUE, pScreen, pScreen); + if (!xf86_config->rotation_damage) + goto bail2; + + /* Assign block/wakeup handler */ + if (!RegisterBlockAndWakeupHandlers (xf86RotateBlockHandler, + xf86RotateWakeupHandler, + (pointer) pScreen)) + { + goto bail3; + } + } + if (0) + { +bail3: + DamageDestroy (xf86_config->rotation_damage); + xf86_config->rotation_damage = NULL; + +bail2: + if (shadow || shadowData) + { + crtc->funcs->shadow_destroy (crtc, shadow, shadowData); + crtc->rotatedPixmap = NULL; + crtc->rotatedData = NULL; + } +bail1: + if (old_width && old_height) + crtc->rotatedPixmap = crtc->funcs->shadow_create (crtc, + NULL, + old_width, + old_height); + return FALSE; + } + } + + /* All done */ + return TRUE; +} diff --git a/hw/xfree86/modes/xf86cvt.c b/hw/xfree86/modes/xf86cvt.c new file mode 100644 index 000000000..69ccc4259 --- /dev/null +++ b/hw/xfree86/modes/xf86cvt.c @@ -0,0 +1,308 @@ +/* + * Copyright 2005-2006 Luc Verhaegen. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * @file This is a copy of xf86cvt.c from the X Server, for compatibility with + * old servers (pre-1.2). + */ + +/* + * The reason for having this function in a file of its own is + * so that ../utils/cvt/cvt can link to it, and that xf86CVTMode + * code is shared directly. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#else +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#endif + +#include "xf86.h" +#include "xf86Modes.h" + +#include <string.h> + +/* + * Generate a CVT standard mode from HDisplay, VDisplay and VRefresh. + * + * These calculations are stolen from the CVT calculation spreadsheet written + * by Graham Loveridge. He seems to be claiming no copyright and there seems to + * be no license attached to this. He apparently just wants to see his name + * mentioned. + * + * This file can be found at http://www.vesa.org/Public/CVT/CVTd6r1.xls + * + * Comments and structure corresponds to the comments and structure of the xls. + * This should ease importing of future changes to the standard (not very + * likely though). + * + * About margins; i'm sure that they are to be the bit between HDisplay and + * HBlankStart, HBlankEnd and HTotal, VDisplay and VBlankStart, VBlankEnd and + * VTotal, where the overscan colour is shown. FB seems to call _all_ blanking + * outside sync "margin" for some reason. Since we prefer seeing proper + * blanking instead of the overscan colour, and since the Crtc* values will + * probably get altered after us, we will disable margins altogether. With + * these calculations, Margins will plainly expand H/VDisplay, and we don't + * want that. -- libv + * + */ +_X_EXPORT DisplayModePtr +xf86CVTMode(int HDisplay, int VDisplay, float VRefresh, Bool Reduced, + Bool Interlaced) +{ + DisplayModeRec *Mode = xnfalloc(sizeof(DisplayModeRec)); + + /* 1) top/bottom margin size (% of height) - default: 1.8 */ +#define CVT_MARGIN_PERCENTAGE 1.8 + + /* 2) character cell horizontal granularity (pixels) - default 8 */ +#define CVT_H_GRANULARITY 8 + + /* 4) Minimum vertical porch (lines) - default 3 */ +#define CVT_MIN_V_PORCH 3 + + /* 4) Minimum number of vertical back porch lines - default 6 */ +#define CVT_MIN_V_BPORCH 6 + + /* Pixel Clock step (kHz) */ +#define CVT_CLOCK_STEP 250 + + Bool Margins = FALSE; + float VFieldRate, HPeriod; + int HDisplayRnd, HMargin; + int VDisplayRnd, VMargin, VSync; + float Interlace; /* Please rename this */ + + memset(Mode, 0, sizeof(DisplayModeRec)); + + /* CVT default is 60.0Hz */ + if (!VRefresh) + VRefresh = 60.0; + + /* 1. Required field rate */ + if (Interlaced) + VFieldRate = VRefresh * 2; + else + VFieldRate = VRefresh; + + /* 2. Horizontal pixels */ + HDisplayRnd = HDisplay - (HDisplay % CVT_H_GRANULARITY); + + /* 3. Determine left and right borders */ + if (Margins) { + /* right margin is actually exactly the same as left */ + HMargin = (((float) HDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0); + HMargin -= HMargin % CVT_H_GRANULARITY; + } else + HMargin = 0; + + /* 4. Find total active pixels */ + Mode->HDisplay = HDisplayRnd + 2*HMargin; + + /* 5. Find number of lines per field */ + if (Interlaced) + VDisplayRnd = VDisplay / 2; + else + VDisplayRnd = VDisplay; + + /* 6. Find top and bottom margins */ + /* nope. */ + if (Margins) + /* top and bottom margins are equal again. */ + VMargin = (((float) VDisplayRnd) * CVT_MARGIN_PERCENTAGE / 100.0); + else + VMargin = 0; + + Mode->VDisplay = VDisplay + 2*VMargin; + + /* 7. Interlace */ + if (Interlaced) + Interlace = 0.5; + else + Interlace = 0.0; + + /* Determine VSync Width from aspect ratio */ + if (!(VDisplay % 3) && ((VDisplay * 4 / 3) == HDisplay)) + VSync = 4; + else if (!(VDisplay % 9) && ((VDisplay * 16 / 9) == HDisplay)) + VSync = 5; + else if (!(VDisplay % 10) && ((VDisplay * 16 / 10) == HDisplay)) + VSync = 6; + else if (!(VDisplay % 4) && ((VDisplay * 5 / 4) == HDisplay)) + VSync = 7; + else if (!(VDisplay % 9) && ((VDisplay * 15 / 9) == HDisplay)) + VSync = 7; + else /* Custom */ + VSync = 10; + + if (!Reduced) { /* simplified GTF calculation */ + + /* 4) Minimum time of vertical sync + back porch interval (µs) + * default 550.0 */ +#define CVT_MIN_VSYNC_BP 550.0 + + /* 3) Nominal HSync width (% of line period) - default 8 */ +#define CVT_HSYNC_PERCENTAGE 8 + + float HBlankPercentage; + int VSyncAndBackPorch, VBackPorch; + int HBlank; + + /* 8. Estimated Horizontal period */ + HPeriod = ((float) (1000000.0 / VFieldRate - CVT_MIN_VSYNC_BP)) / + (VDisplayRnd + 2 * VMargin + CVT_MIN_V_PORCH + Interlace); + + /* 9. Find number of lines in sync + backporch */ + if (((int)(CVT_MIN_VSYNC_BP / HPeriod) + 1) < (VSync + CVT_MIN_V_PORCH)) + VSyncAndBackPorch = VSync + CVT_MIN_V_PORCH; + else + VSyncAndBackPorch = (int)(CVT_MIN_VSYNC_BP / HPeriod) + 1; + + /* 10. Find number of lines in back porch */ + VBackPorch = VSyncAndBackPorch - VSync; + + /* 11. Find total number of lines in vertical field */ + Mode->VTotal = VDisplayRnd + 2 * VMargin + VSyncAndBackPorch + Interlace + + CVT_MIN_V_PORCH; + + /* 5) Definition of Horizontal blanking time limitation */ + /* Gradient (%/kHz) - default 600 */ +#define CVT_M_FACTOR 600 + + /* Offset (%) - default 40 */ +#define CVT_C_FACTOR 40 + + /* Blanking time scaling factor - default 128 */ +#define CVT_K_FACTOR 128 + + /* Scaling factor weighting - default 20 */ +#define CVT_J_FACTOR 20 + +#define CVT_M_PRIME CVT_M_FACTOR * CVT_K_FACTOR / 256 +#define CVT_C_PRIME (CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \ + CVT_J_FACTOR + + /* 12. Find ideal blanking duty cycle from formula */ + HBlankPercentage = CVT_C_PRIME - CVT_M_PRIME * HPeriod/1000.0; + + /* 13. Blanking time */ + if (HBlankPercentage < 20) + HBlankPercentage = 20; + + HBlank = Mode->HDisplay * HBlankPercentage/(100.0 - HBlankPercentage); + HBlank -= HBlank % (2*CVT_H_GRANULARITY); + + /* 14. Find total number of pixels in a line. */ + Mode->HTotal = Mode->HDisplay + HBlank; + + /* Fill in HSync values */ + Mode->HSyncEnd = Mode->HDisplay + HBlank / 2; + + Mode->HSyncStart = Mode->HSyncEnd - + (Mode->HTotal * CVT_HSYNC_PERCENTAGE) / 100; + Mode->HSyncStart += CVT_H_GRANULARITY - + Mode->HSyncStart % CVT_H_GRANULARITY; + + /* Fill in VSync values */ + Mode->VSyncStart = Mode->VDisplay + CVT_MIN_V_PORCH; + Mode->VSyncEnd = Mode->VSyncStart + VSync; + + } else { /* Reduced blanking */ + /* Minimum vertical blanking interval time (µs) - default 460 */ +#define CVT_RB_MIN_VBLANK 460.0 + + /* Fixed number of clocks for horizontal sync */ +#define CVT_RB_H_SYNC 32.0 + + /* Fixed number of clocks for horizontal blanking */ +#define CVT_RB_H_BLANK 160.0 + + /* Fixed number of lines for vertical front porch - default 3 */ +#define CVT_RB_VFPORCH 3 + + int VBILines; + + /* 8. Estimate Horizontal period. */ + HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / + (VDisplayRnd + 2*VMargin); + + /* 9. Find number of lines in vertical blanking */ + VBILines = ((float) CVT_RB_MIN_VBLANK) / HPeriod + 1; + + /* 10. Check if vertical blanking is sufficient */ + if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH)) + VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH; + + /* 11. Find total number of lines in vertical field */ + Mode->VTotal = VDisplayRnd + 2 * VMargin + Interlace + VBILines; + + /* 12. Find total number of pixels in a line */ + Mode->HTotal = Mode->HDisplay + CVT_RB_H_BLANK; + + /* Fill in HSync values */ + Mode->HSyncEnd = Mode->HDisplay + CVT_RB_H_BLANK / 2; + Mode->HSyncStart = Mode->HSyncEnd - CVT_RB_H_SYNC; + + /* Fill in VSync values */ + Mode->VSyncStart = Mode->VDisplay + CVT_RB_VFPORCH; + Mode->VSyncEnd = Mode->VSyncStart + VSync; + } + + /* 15/13. Find pixel clock frequency (kHz for xf86) */ + Mode->Clock = Mode->HTotal * 1000.0 / HPeriod; + Mode->Clock -= Mode->Clock % CVT_CLOCK_STEP; + + /* 16/14. Find actual Horizontal Frequency (kHz) */ + Mode->HSync = ((float) Mode->Clock) / ((float) Mode->HTotal); + + /* 17/15. Find actual Field rate */ + Mode->VRefresh = (1000.0 * ((float) Mode->Clock)) / + ((float) (Mode->HTotal * Mode->VTotal)); + + /* 18/16. Find actual vertical frame frequency */ + /* ignore - just set the mode flag for interlaced */ + if (Interlaced) + Mode->VTotal *= 2; + + { + char Name[256]; + Name[0] = 0; + + snprintf(Name, 256, "%dx%d", HDisplay, VDisplay); + + Mode->name = xnfalloc(strlen(Name) + 1); + memcpy(Mode->name, Name, strlen(Name) + 1); + } + + if (Reduced) + Mode->Flags |= V_PHSYNC | V_NVSYNC; + else + Mode->Flags |= V_NHSYNC | V_PVSYNC; + + if (Interlaced) + Mode->Flags |= V_INTERLACE; + + return Mode; +} diff --git a/hw/xfree86/os-support/bus/axpPci.c b/hw/xfree86/os-support/bus/axpPci.c index 1f1547798..e2f086c53 100644 --- a/hw/xfree86/os-support/bus/axpPci.c +++ b/hw/xfree86/os-support/bus/axpPci.c @@ -217,7 +217,8 @@ axpPciInit() * only set up the root bus for each domain (hose) and the bridged * buses will be set up as they are found. */ - bus = PCI_MAKE_BUS(domain, 0); + /* make a bus with both the domain and the root bus in it */ + bus = PCI_MAKE_BUS(domain, pDomain->root_bus); pciBusInfo[bus] = xnfalloc(sizeof(pciBusInfo_t)); (void)memset(pciBusInfo[bus], 0, sizeof(pciBusInfo_t)); @@ -246,7 +247,7 @@ axpPciBusFromTag(PCITAG tag) || !(pDomain = pBusInfo->pciBusPriv) || (pDomain->domain != PCI_DOM_FROM_TAG(tag))) return -1; - bus = PCI_BUS_NO_DOMAIN(bus) + pDomain->root_bus; + bus = PCI_BUS_NO_DOMAIN(bus); /* should just be root_bus */ dfn = PCI_DFN_FROM_TAG(tag); if (_iobase(IOBASE_HOSE, -1, bus, dfn) != pDomain->hose) return -1; diff --git a/hw/xfree86/os-support/shared/libc_wrapper.c b/hw/xfree86/os-support/shared/libc_wrapper.c index 4c4af4c24..a459d5d70 100644 --- a/hw/xfree86/os-support/shared/libc_wrapper.c +++ b/hw/xfree86/os-support/shared/libc_wrapper.c @@ -628,7 +628,7 @@ typedef struct _xf86_file_ { char* fname; } XF86FILE_priv; -XF86FILE_priv stdhnd[3] = { +static XF86FILE_priv stdhnd[3] = { { 0, XF86FILE_magic, NULL, "$stdinp$" }, { 0, XF86FILE_magic, NULL, "$stdout$" }, { 0, XF86FILE_magic, NULL, "$stderr$" } diff --git a/hw/xfree86/os-support/solaris/Makefile.am b/hw/xfree86/os-support/solaris/Makefile.am index 57ec89e57..d01e2e676 100644 --- a/hw/xfree86/os-support/solaris/Makefile.am +++ b/hw/xfree86/os-support/solaris/Makefile.am @@ -19,9 +19,9 @@ solaris-$(SOLARIS_INOUT_ARCH).il: solaris-${SOLARIS_INOUT_ARCH}.S noinst_LTLIBRARIES = libsolaris.la libsolaris_la_SOURCES = sun_bios.c sun_init.c \ - sun_mouse.c sun_vid.c sun_bell.c $(AGP_SRC) \ + sun_mouse.c sun_vid.c sun_bell.c $(AGP_SRC) sun_apm.c \ $(srcdir)/../shared/libc_wrapper.c \ - $(srcdir)/../shared/kmod_noop.c $(srcdir)/../shared/pm_noop.c \ + $(srcdir)/../shared/kmod_noop.c \ $(srcdir)/../shared/posix_tty.c $(srcdir)/../shared/sigiostubs.c \ $(srcdir)/../shared/stdPci.c $(srcdir)/../shared/stdResource.c \ $(VTSW_SRC) diff --git a/hw/xfree86/os-support/solaris/sun_apm.c b/hw/xfree86/os-support/solaris/sun_apm.c new file mode 100644 index 000000000..a9657fd55 --- /dev/null +++ b/hw/xfree86/os-support/solaris/sun_apm.c @@ -0,0 +1,232 @@ +/* Based on hw/xfree86/os-support/bsd/bsd_apm.c which bore no explicit + * copyright notice, so is covered by the following notice: + * + * Copyright (C) 1994-2003 The XFree86 Project, Inc. All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF + * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Except as contained in this notice, the name of the XFree86 Project shall + * not be used in advertising or otherwise to promote the sale, use or other + * dealings in this Software without prior written authorization from the + * XFree86 Project. + */ + +/* Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons + * to whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT + * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR 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. + * + * Except as contained in this notice, the name of a copyright holder + * shall not be used in advertising or otherwise to promote the sale, use + * or other dealings in this Software without prior written authorization + * of the copyright holder. + */ + +#ifdef HAVE_XORG_CONFIG_H +#include <xorg-config.h> +#endif + +#include <X11/X.h> +#include "os.h" +#include "xf86.h" +#include "xf86Priv.h" +#define XF86_OS_PRIVS +#include "xf86_OSproc.h" +#include "xf86_OSlib.h" + +#ifndef PLEASE_FIX_THIS +#define APM_STANDBY_REQ 0xa01 +#define APM_SUSPEND_REQ 0xa02 +#define APM_NORMAL_RESUME 0xa03 +#define APM_CRIT_RESUME 0xa04 +#define APM_BATTERY_LOW 0xa05 +#define APM_POWER_CHANGE 0xa06 +#define APM_UPDATE_TIME 0xa07 +#define APM_CRIT_SUSPEND_REQ 0xa08 +#define APM_USER_STANDBY_REQ 0xa09 +#define APM_USER_SUSPEND_REQ 0xa0a +#define APM_SYS_STANDBY_RESUME 0xa0b +#define APM_IOC_NEXTEVENT 0xa0c +#define APM_IOC_RESUME 0xa0d +#define APM_IOC_SUSPEND 0xa0e +#define APM_IOC_STANDBY 0xa0f +#endif + +typedef struct apm_event_info +{ + int type; +} apm_event_info; + +/* + This may be replaced with a better device name + very soon... +*/ +#define APM_DEVICE "/dev/srn" +#define APM_DEVICE1 "/dev/apm" + +static pointer APMihPtr = NULL; +static void sunCloseAPM(void); + +static struct { + u_int apmBsd; + pmEvent xf86; +} sunToXF86Array [] = { + { APM_STANDBY_REQ, XF86_APM_SYS_STANDBY }, + { APM_SUSPEND_REQ, XF86_APM_SYS_SUSPEND }, + { APM_NORMAL_RESUME, XF86_APM_NORMAL_RESUME }, + { APM_CRIT_RESUME, XF86_APM_CRITICAL_RESUME }, + { APM_BATTERY_LOW, XF86_APM_LOW_BATTERY }, + { APM_POWER_CHANGE, XF86_APM_POWER_STATUS_CHANGE }, + { APM_UPDATE_TIME, XF86_APM_UPDATE_TIME }, + { APM_CRIT_SUSPEND_REQ, XF86_APM_CRITICAL_SUSPEND }, + { APM_USER_STANDBY_REQ, XF86_APM_USER_STANDBY }, + { APM_USER_SUSPEND_REQ, XF86_APM_USER_SUSPEND }, + { APM_SYS_STANDBY_RESUME, XF86_APM_STANDBY_RESUME }, +#ifdef APM_CAPABILITY_CHANGE + { APM_CAPABILITY_CHANGE, XF86_APM_CAPABILITY_CHANGED }, +#endif +}; + +#define numApmEvents (sizeof(sunToXF86Array) / sizeof(sunToXF86Array[0])) + +static pmEvent +sunToXF86(int type) +{ + int i; + + for (i = 0; i < numApmEvents; i++) { + if (type == sunToXF86Array[i].apmBsd) { + return sunToXF86Array[i].xf86; + } + } + return XF86_APM_UNKNOWN; +} + +/* + * APM events can be requested direclty from /dev/apm + */ +static int +sunPMGetEventFromOS(int fd, pmEvent *events, int num) +{ + struct apm_event_info sunEvent; + int i; + + for (i = 0; i < num; i++) { + + if (ioctl(fd, APM_IOC_NEXTEVENT, &sunEvent) < 0) { + if (errno != EAGAIN) { + xf86Msg(X_WARNING, "sunPMGetEventFromOS: APM_IOC_NEXTEVENT" + " errno = %d\n", errno); + } + break; + } + events[i] = sunToXF86(sunEvent.type); + } + xf86Msg(X_WARNING, "Got some events\n"); + return i; +} + +static pmWait +sunPMConfirmEventToOs(int fd, pmEvent event) +{ + switch (event) { +/* XXX: NOT CURRENTLY RETURNED FROM OS */ + case XF86_APM_SYS_STANDBY: + case XF86_APM_USER_STANDBY: + if (ioctl( fd, APM_IOC_STANDBY, NULL ) == 0) + return PM_WAIT; /* should we stop the Xserver in standby, too? */ + else + return PM_NONE; + case XF86_APM_SYS_SUSPEND: + case XF86_APM_CRITICAL_SUSPEND: + case XF86_APM_USER_SUSPEND: + xf86Msg(X_WARNING, "Got SUSPENDED\n"); + if (ioctl( fd, APM_IOC_SUSPEND, NULL ) == 0) + return PM_CONTINUE; + else { + xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_SUSPEND" + " errno = %d\n", errno); + return PM_FAILED; + } + case XF86_APM_STANDBY_RESUME: + case XF86_APM_NORMAL_RESUME: + case XF86_APM_CRITICAL_RESUME: + case XF86_APM_STANDBY_FAILED: + case XF86_APM_SUSPEND_FAILED: + xf86Msg(X_WARNING, "Got RESUME\n"); + if (ioctl( fd, APM_IOC_RESUME, NULL ) == 0) + return PM_CONTINUE; + else { + xf86Msg(X_WARNING, "sunPMConfirmEventToOs: APM_IOC_RESUME" + " errno = %d\n", errno); + return PM_FAILED; + } + default: + return PM_NONE; + } +} + +PMClose +xf86OSPMOpen(void) +{ + int fd; + + if (APMihPtr || !xf86Info.pmFlag) { + return NULL; + } + + if ((fd = open(APM_DEVICE, O_RDWR)) == -1) { + if ((fd = open(APM_DEVICE1, O_RDWR)) == -1) { + return NULL; + } + } + xf86PMGetEventFromOs = sunPMGetEventFromOS; + xf86PMConfirmEventToOs = sunPMConfirmEventToOs; + APMihPtr = xf86AddInputHandler(fd, xf86HandlePMEvents, NULL); + return sunCloseAPM; +} + +static void +sunCloseAPM(void) +{ + int fd; + + if (APMihPtr) { + fd = xf86RemoveInputHandler(APMihPtr); + close(fd); + APMihPtr = NULL; + } +} diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h index 97f872301..27f766d9c 100644 --- a/hw/xfree86/os-support/xf86_OSlib.h +++ b/hw/xfree86/os-support/xf86_OSlib.h @@ -130,8 +130,8 @@ typedef signed long xf86ssize_t; # include <errno.h> # if defined(_NEED_SYSI86) -# include <sys/immu.h> # if !(defined (sun) && defined (SVR4)) +# include <sys/immu.h> # include <sys/region.h> # endif # include <sys/proc.h> diff --git a/hw/xfree86/parser/DRI.c b/hw/xfree86/parser/DRI.c index dc75cd23f..18644bcc7 100644 --- a/hw/xfree86/parser/DRI.c +++ b/hw/xfree86/parser/DRI.c @@ -48,7 +48,21 @@ static xf86ConfigSymTabRec DRITab[] = #define CLEANUP xf86freeBuffersList -XF86ConfBuffersPtr +static void +xf86freeBuffersList (XF86ConfBuffersPtr ptr) +{ + XF86ConfBuffersPtr prev; + + while (ptr) { + TestFree (ptr->buf_flags); + TestFree (ptr->buf_comment); + prev = ptr; + ptr = ptr->list.next; + xf86conffree (prev); + } +} + +static XF86ConfBuffersPtr xf86parseBuffers (void) { int token; @@ -169,18 +183,3 @@ xf86freeDRI (XF86ConfDRIPtr ptr) TestFree (ptr->dri_comment); xf86conffree (ptr); } - -void -xf86freeBuffersList (XF86ConfBuffersPtr ptr) -{ - XF86ConfBuffersPtr prev; - - while (ptr) { - TestFree (ptr->buf_flags); - TestFree (ptr->buf_comment); - prev = ptr; - ptr = ptr->list.next; - xf86conffree (prev); - } -} - diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c index 7ab70d1a8..4adea1ade 100644 --- a/hw/xfree86/parser/Flags.c +++ b/hw/xfree86/parser/Flags.c @@ -441,15 +441,6 @@ xf86uLongToString(unsigned long i) return s; } -void -xf86debugListOptions(XF86OptionPtr Options) -{ - while (Options) { - ErrorF("Option: %s Value: %s\n",Options->opt_name,Options->opt_val); - Options = Options->list.next; - } -} - XF86OptionPtr xf86parseOption(XF86OptionPtr head) { diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c index b9f4e9e6a..5d1348acb 100644 --- a/hw/xfree86/parser/Layout.c +++ b/hw/xfree86/parser/Layout.c @@ -382,24 +382,7 @@ xf86printLayoutSection (FILE * cf, XF86ConfLayoutPtr ptr) } } -void -xf86freeLayoutList (XF86ConfLayoutPtr ptr) -{ - XF86ConfLayoutPtr prev; - - while (ptr) - { - TestFree (ptr->lay_identifier); - TestFree (ptr->lay_comment); - xf86freeAdjacencyList (ptr->lay_adjacency_lst); - xf86freeInputrefList (ptr->lay_input_lst); - prev = ptr; - ptr = ptr->list.next; - xf86conffree (prev); - } -} - -void +static void xf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr) { XF86ConfAdjacencyPtr prev; @@ -419,7 +402,7 @@ xf86freeAdjacencyList (XF86ConfAdjacencyPtr ptr) } -void +static void xf86freeInputrefList (XF86ConfInputrefPtr ptr) { XF86ConfInputrefPtr prev; @@ -435,6 +418,23 @@ xf86freeInputrefList (XF86ConfInputrefPtr ptr) } +void +xf86freeLayoutList (XF86ConfLayoutPtr ptr) +{ + XF86ConfLayoutPtr prev; + + while (ptr) + { + TestFree (ptr->lay_identifier); + TestFree (ptr->lay_comment); + xf86freeAdjacencyList (ptr->lay_adjacency_lst); + xf86freeInputrefList (ptr->lay_input_lst); + prev = ptr; + ptr = ptr->list.next; + xf86conffree (prev); + } +} + #define CheckScreen(str, ptr)\ if (str[0] != '\0') \ { \ diff --git a/hw/xfree86/parser/Makefile.am b/hw/xfree86/parser/Makefile.am index 1c1ba3f13..849ee8bab 100644 --- a/hw/xfree86/parser/Makefile.am +++ b/hw/xfree86/parser/Makefile.am @@ -36,4 +36,6 @@ EXTRA_DIST = \ cpconfig.c sdk_HEADERS = \ - $(LIBHEADERS) + $(LIBHEADERS) \ + xf86Parser.h \ + xf86Optrec.h diff --git a/hw/xfree86/parser/Module.c b/hw/xfree86/parser/Module.c index f3ed9d19f..81eff18ae 100644 --- a/hw/xfree86/parser/Module.c +++ b/hw/xfree86/parser/Module.c @@ -83,7 +83,7 @@ static xf86ConfigSymTabRec ModuleTab[] = #define CLEANUP xf86freeModules -XF86LoadPtr +static XF86LoadPtr xf86parseModuleSubSection (XF86LoadPtr head, char *name) { int token; diff --git a/hw/xfree86/parser/Monitor.c b/hw/xfree86/parser/Monitor.c index 9dd0b1b1c..4bff4b23b 100644 --- a/hw/xfree86/parser/Monitor.c +++ b/hw/xfree86/parser/Monitor.c @@ -124,7 +124,21 @@ static xf86ConfigSymTabRec ModeTab[] = #define CLEANUP xf86freeModeLineList -XF86ConfModeLinePtr +static void +xf86freeModeLineList (XF86ConfModeLinePtr ptr) +{ + XF86ConfModeLinePtr prev; + while (ptr) + { + TestFree (ptr->ml_identifier); + TestFree (ptr->ml_comment); + prev = ptr; + ptr = ptr->list.next; + xf86conffree (prev); + } +} + +static XF86ConfModeLinePtr xf86parseModeLine (void) { int token; @@ -253,7 +267,7 @@ xf86parseModeLine (void) return (ptr); } -XF86ConfModeLinePtr +static XF86ConfModeLinePtr xf86parseVerboseMode (void) { int token, token2; @@ -830,20 +844,6 @@ xf86freeModesList (XF86ConfModesPtr ptr) } } -void -xf86freeModeLineList (XF86ConfModeLinePtr ptr) -{ - XF86ConfModeLinePtr prev; - while (ptr) - { - TestFree (ptr->ml_identifier); - TestFree (ptr->ml_comment); - prev = ptr; - ptr = ptr->list.next; - xf86conffree (prev); - } -} - XF86ConfMonitorPtr xf86findMonitor (const char *ident, XF86ConfMonitorPtr p) { diff --git a/hw/xfree86/parser/Screen.c b/hw/xfree86/parser/Screen.c index b7a64b035..79e1d24ef 100644 --- a/hw/xfree86/parser/Screen.c +++ b/hw/xfree86/parser/Screen.c @@ -83,7 +83,7 @@ static xf86ConfigSymTabRec DisplayTab[] = #define CLEANUP xf86freeDisplayList -XF86ConfDisplayPtr +static XF86ConfDisplayPtr xf86parseDisplaySubSection (void) { int token; diff --git a/hw/xfree86/parser/Vendor.c b/hw/xfree86/parser/Vendor.c index 3e9358b3b..d1e608067 100644 --- a/hw/xfree86/parser/Vendor.c +++ b/hw/xfree86/parser/Vendor.c @@ -75,7 +75,7 @@ static xf86ConfigSymTabRec VendorSubTab[] = #define CLEANUP xf86freeVendorSubList -XF86ConfVendSubPtr +static XF86ConfVendSubPtr xf86parseVendorSubSection (void) { int has_ident = FALSE; @@ -242,16 +242,3 @@ xf86freeVendorSubList (XF86ConfVendSubPtr ptr) xf86conffree (prev); } } - -XF86ConfVendorPtr -xf86findVendor (const char *name, XF86ConfVendorPtr list) -{ - while (list) - { - if (xf86nameCompare (list->vnd_identifier, name) == 0) - return (list); - list = list->list.next; - } - return (NULL); -} - diff --git a/hw/xfree86/parser/Video.c b/hw/xfree86/parser/Video.c index fa0ff7833..a8912cf44 100644 --- a/hw/xfree86/parser/Video.c +++ b/hw/xfree86/parser/Video.c @@ -74,7 +74,23 @@ static xf86ConfigSymTabRec VideoPortTab[] = #define CLEANUP xf86freeVideoPortList -XF86ConfVideoPortPtr +static void +xf86freeVideoPortList (XF86ConfVideoPortPtr ptr) +{ + XF86ConfVideoPortPtr prev; + + while (ptr) + { + TestFree (ptr->vp_identifier); + TestFree (ptr->vp_comment); + xf86optionListFree (ptr->vp_option_lst); + prev = ptr; + ptr = ptr->list.next; + xf86conffree (prev); + } +} + +static XF86ConfVideoPortPtr xf86parseVideoPortSubSection (void) { int has_ident = FALSE; @@ -266,22 +282,6 @@ xf86freeVideoAdaptorList (XF86ConfVideoAdaptorPtr ptr) } } -void -xf86freeVideoPortList (XF86ConfVideoPortPtr ptr) -{ - XF86ConfVideoPortPtr prev; - - while (ptr) - { - TestFree (ptr->vp_identifier); - TestFree (ptr->vp_comment); - xf86optionListFree (ptr->vp_option_lst); - prev = ptr; - ptr = ptr->list.next; - xf86conffree (prev); - } -} - XF86ConfVideoAdaptorPtr xf86findVideoAdaptor (const char *ident, XF86ConfVideoAdaptorPtr p) { diff --git a/hw/xfree86/parser/configProcs.h b/hw/xfree86/parser/configProcs.h index 0b989054b..3c9ce7a83 100644 --- a/hw/xfree86/parser/configProcs.h +++ b/hw/xfree86/parser/configProcs.h @@ -49,30 +49,23 @@ int xf86validateInput (XF86ConfigPtr p); XF86ConfLayoutPtr xf86parseLayoutSection(void); void xf86printLayoutSection(FILE *cf, XF86ConfLayoutPtr ptr); void xf86freeLayoutList(XF86ConfLayoutPtr ptr); -void xf86freeAdjacencyList(XF86ConfAdjacencyPtr ptr); -void xf86freeInputrefList(XF86ConfInputrefPtr ptr); int xf86validateLayout(XF86ConfigPtr p); /* Module.c */ -XF86LoadPtr xf86parseModuleSubSection(XF86LoadPtr head, char *name); XF86ConfModulePtr xf86parseModuleSection(void); void xf86printModuleSection(FILE *cf, XF86ConfModulePtr ptr); XF86LoadPtr xf86addNewLoadDirective(XF86LoadPtr head, char *name, int type, XF86OptionPtr opts); void xf86freeModules(XF86ConfModulePtr ptr); /* Monitor.c */ -XF86ConfModeLinePtr xf86parseModeLine(void); -XF86ConfModeLinePtr xf86parseVerboseMode(void); XF86ConfMonitorPtr xf86parseMonitorSection(void); XF86ConfModesPtr xf86parseModesSection(void); void xf86printMonitorSection(FILE *cf, XF86ConfMonitorPtr ptr); void xf86printModesSection(FILE *cf, XF86ConfModesPtr ptr); void xf86freeMonitorList(XF86ConfMonitorPtr ptr); void xf86freeModesList(XF86ConfModesPtr ptr); -void xf86freeModeLineList(XF86ConfModeLinePtr ptr); int xf86validateMonitor(XF86ConfigPtr p, XF86ConfScreenPtr screen); /* Pointer.c */ XF86ConfInputPtr xf86parsePointerSection(void); /* Screen.c */ -XF86ConfDisplayPtr xf86parseDisplaySubSection(void); XF86ConfScreenPtr xf86parseScreenSection(void); void xf86printScreenSection(FILE *cf, XF86ConfScreenPtr ptr); void xf86freeScreenList(XF86ConfScreenPtr ptr); @@ -82,34 +75,25 @@ void xf86freeModeList(XF86ModePtr ptr); int xf86validateScreen(XF86ConfigPtr p); /* Vendor.c */ XF86ConfVendorPtr xf86parseVendorSection(void); -XF86ConfVendSubPtr xf86parseVendorSubSection (void); void xf86freeVendorList(XF86ConfVendorPtr p); void xf86printVendorSection(FILE * cf, XF86ConfVendorPtr ptr); void xf86freeVendorSubList (XF86ConfVendSubPtr ptr); /* Video.c */ -XF86ConfVideoPortPtr xf86parseVideoPortSubSection(void); XF86ConfVideoAdaptorPtr xf86parseVideoAdaptorSection(void); void xf86printVideoAdaptorSection(FILE *cf, XF86ConfVideoAdaptorPtr ptr); void xf86freeVideoAdaptorList(XF86ConfVideoAdaptorPtr ptr); -void xf86freeVideoPortList(XF86ConfVideoPortPtr ptr); -/* read.c */ -int xf86validateConfig(XF86ConfigPtr p); /* scan.c */ -unsigned int xf86strToUL(char *str); int xf86getToken(xf86ConfigSymTabRec *tab); int xf86getSubToken(char **comment); int xf86getSubTokenWithTab(char **comment, xf86ConfigSymTabRec *tab); void xf86unGetToken(int token); char *xf86tokenString(void); void xf86parseError(char *format, ...); -void xf86parseWarning(char *format, ...); void xf86validationError(char *format, ...); void xf86setSection(char *section); int xf86getStringToken(xf86ConfigSymTabRec *tab); /* write.c */ /* DRI.c */ -XF86ConfBuffersPtr xf86parseBuffers (void); -void xf86freeBuffersList (XF86ConfBuffersPtr ptr); XF86ConfDRIPtr xf86parseDRISection (void); void xf86printDRISection (FILE * cf, XF86ConfDRIPtr ptr); void xf86freeDRI (XF86ConfDRIPtr ptr); diff --git a/hw/xfree86/parser/read.c b/hw/xfree86/parser/read.c index b6b3bc377..9f79696ac 100644 --- a/hw/xfree86/parser/read.c +++ b/hw/xfree86/parser/read.c @@ -73,6 +73,25 @@ static xf86ConfigSymTabRec TopLevelTab[] = #define CLEANUP xf86freeConfig +/* + * This function resolves name references and reports errors if the named + * objects cannot be found. + */ +static int +xf86validateConfig (XF86ConfigPtr p) +{ + if (!xf86validateDevice (p)) + return FALSE; + if (!xf86validateScreen (p)) + return FALSE; + if (!xf86validateInput (p)) + return FALSE; + if (!xf86validateLayout (p)) + return FALSE; + + return (TRUE); +} + XF86ConfigPtr xf86readConfigFile (void) { @@ -219,25 +238,6 @@ xf86readConfigFile (void) #undef CLEANUP /* - * This function resolves name references and reports errors if the named - * objects cannot be found. - */ -int -xf86validateConfig (XF86ConfigPtr p) -{ - if (!xf86validateDevice (p)) - return FALSE; - if (!xf86validateScreen (p)) - return FALSE; - if (!xf86validateInput (p)) - return FALSE; - if (!xf86validateLayout (p)) - return FALSE; - - return (TRUE); -} - -/* * adds an item to the end of the linked list. Any record whose first field * is a GenericListRec can be cast to this type and used with this function. * A pointer to the head of the list is returned to handle the addition of diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c index f81c45afe..68e7ec650 100644 --- a/hw/xfree86/parser/scan.c +++ b/hw/xfree86/parser/scan.c @@ -116,7 +116,7 @@ extern char *__XOS2RedirRoot(char *path); * A portable, but restricted, version of strtoul(). It only understands * hex, octal, and decimal. But it's good enough for our needs. */ -unsigned int +static unsigned int xf86strToUL (char *str) { int base = 10; @@ -922,20 +922,6 @@ xf86parseError (char *format,...) } void -xf86parseWarning (char *format,...) -{ - va_list ap; - - ErrorF ("Parse warning on line %d of section %s in file %s\n\t", - configLineNo, configSection, configPath); - va_start (ap, format); - VErrorF (format, ap); - va_end (ap); - - ErrorF ("\n"); -} - -void xf86validationError (char *format,...) { va_list ap; diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h index a6829273c..89de97bbb 100644 --- a/hw/xfree86/parser/xf86Parser.h +++ b/hw/xfree86/parser/xf86Parser.h @@ -469,7 +469,6 @@ XF86ConfModeLinePtr xf86findModeLine(const char *ident, XF86ConfModeLinePtr p); XF86ConfScreenPtr xf86findScreen(const char *ident, XF86ConfScreenPtr p); XF86ConfInputPtr xf86findInput(const char *ident, XF86ConfInputPtr p); XF86ConfInputPtr xf86findInputByDriver(const char *driver, XF86ConfInputPtr p); -XF86ConfVendorPtr xf86findVendor(const char *name, XF86ConfVendorPtr list); XF86ConfVideoAdaptorPtr xf86findVideoAdaptor(const char *ident, XF86ConfVideoAdaptorPtr p); diff --git a/hw/xfree86/ramdac/Makefile.am b/hw/xfree86/ramdac/Makefile.am index 8d944455f..2b84cb4dd 100644 --- a/hw/xfree86/ramdac/Makefile.am +++ b/hw/xfree86/ramdac/Makefile.am @@ -1,8 +1,6 @@ -module_LTLIBRARIES = libramdac.la +noinst_LIBRARIES = libramdac.a -libramdac_la_LDFLAGS = -avoid-version - -libramdac_la_SOURCES = xf86RamDacMod.c xf86RamDac.c xf86RamDacCmap.c \ +libramdac_a_SOURCES = xf86RamDac.c xf86RamDacCmap.c \ xf86Cursor.c xf86HWCurs.c IBM.c BT.c TI.c \ xf86BitOrder.c diff --git a/hw/xfree86/ramdac/xf86Cursor.c b/hw/xfree86/ramdac/xf86Cursor.c index a903f7f02..457807698 100644 --- a/hw/xfree86/ramdac/xf86Cursor.c +++ b/hw/xfree86/ramdac/xf86Cursor.c @@ -199,10 +199,11 @@ xf86CursorEnableDisableFBAccess( pScreen->devPrivates[xf86CursorScreenIndex].ptr; if (!enable && ScreenPriv->CurrentCursor != NullCursor) { - ScreenPriv->SavedCursor = ScreenPriv->CurrentCursor; + CursorPtr currentCursor = ScreenPriv->CurrentCursor; xf86CursorSetCursor(pScreen, NullCursor, ScreenPriv->x, ScreenPriv->y); ScreenPriv->isUp = FALSE; ScreenPriv->SWCursor = TRUE; + ScreenPriv->SavedCursor = currentCursor; } if (ScreenPriv->EnableDisableFBAccess) diff --git a/hw/xfree86/ramdac/xf86Cursor.h b/hw/xfree86/ramdac/xf86Cursor.h index 08cca6b96..469f48f01 100644 --- a/hw/xfree86/ramdac/xf86Cursor.h +++ b/hw/xfree86/ramdac/xf86Cursor.h @@ -44,5 +44,8 @@ void xf86ForceHWCursor (ScreenPtr pScreen, Bool on); #define HARDWARE_CURSOR_NIBBLE_SWAPPED 0x00000800 #define HARDWARE_CURSOR_SHOW_TRANSPARENT 0x00001000 #define HARDWARE_CURSOR_UPDATE_UNHIDDEN 0x00002000 +#ifdef ARGB_CURSOR +#define HARDWARE_CURSOR_ARGB 0x00004000 +#endif #endif /* _XF86CURSOR_H */ diff --git a/hw/xfree86/ramdac/xf86RamDacMod.c b/hw/xfree86/ramdac/xf86RamDacMod.c deleted file mode 100644 index b4187a953..000000000 --- a/hw/xfree86/ramdac/xf86RamDacMod.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 1998 by Alan Hourihane, Wigan, England. - * - * 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 Alan Hourihane not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Alan Hourihane makes no representations - * about the suitability of this software for any purpose. It is provided - * "as is" without express or implied warranty. - * - * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL ALAN HOURIHANE 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. - * - * Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk> - * - * Generic RAMDAC module. - */ - -#ifdef HAVE_XORG_CONFIG_H -#include <xorg-config.h> -#endif - -#include "xf86Module.h" - -static XF86ModuleVersionInfo VersRec = { - "ramdac", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - 0, 1, 0, - ABI_CLASS_VIDEODRV, - ABI_VIDEODRV_VERSION, - MOD_CLASS_NONE, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData ramdacModuleData = { &VersRec, NULL, NULL }; diff --git a/hw/xfree86/x86emu/prim_ops.c b/hw/xfree86/x86emu/prim_ops.c index 461e09e3e..b9e7257ca 100644 --- a/hw/xfree86/x86emu/prim_ops.c +++ b/hw/xfree86/x86emu/prim_ops.c @@ -2082,7 +2082,7 @@ Implements the IMUL instruction and side effects. void imul_long_direct(u32 *res_lo, u32* res_hi,u32 d, u32 s) { #ifdef __HAS_LONG_LONG__ - s64 res = (s32)d * (s32)s; + s64 res = (s64)(s32)d * (s32)s; *res_lo = (u32)res; *res_hi = (u32)(res >> 32); @@ -2174,7 +2174,7 @@ Implements the MUL instruction and side effects. void mul_long(u32 s) { #ifdef __HAS_LONG_LONG__ - u64 res = (u32)M.x86.R_EAX * (u32)s; + u64 res = (u64)M.x86.R_EAX * s; M.x86.R_EAX = (u32)res; M.x86.R_EDX = (u32)(res >> 32); diff --git a/hw/xfree86/xaa/Makefile.am b/hw/xfree86/xaa/Makefile.am index 5d529b118..6ed8303a4 100644 --- a/hw/xfree86/xaa/Makefile.am +++ b/hw/xfree86/xaa/Makefile.am @@ -9,6 +9,7 @@ MSB_3_FIXED = mf3-xaaBitmap.c mf3-xaaStipple.c POLYSEG = s-xaaLine.c s-xaaDashLine.c libxaa_la_LDFLAGS = -avoid-version +libxaa_la_LIBADD = $(top_builddir)/miext/cw/libcw.la module_LTLIBRARIES = libxaa.la libxaa_la_SOURCES = xaaInit.c xaaGC.c xaaInitAccel.c xaaFallback.c \ diff --git a/hw/xfree86/xaa/xaaInit.c b/hw/xfree86/xaa/xaaInit.c index 1542fc26e..79a0e4ceb 100644 --- a/hw/xfree86/xaa/xaaInit.c +++ b/hw/xfree86/xaa/xaaInit.c @@ -227,6 +227,14 @@ XAAInit(ScreenPtr pScreen, XAAInfoRecPtr infoRec) if(infoRec->Flags & MICROSOFT_ZERO_LINE_BIAS) miSetZeroLineBias(pScreen, OCTANT1 | OCTANT2 | OCTANT3 | OCTANT4); +#ifdef COMPOSITE + /* Initialize the composite wrapper. This needs to happen after the + * wrapping above (so it comes before us), but before all other extensions, + * so it doesn't confuse them. (particularly damage). + */ + miInitializeCompositeWrapper(pScreen); +#endif + return TRUE; } diff --git a/hw/xfree86/xf4bpp/Makefile.am b/hw/xfree86/xf4bpp/Makefile.am index 8fddb6b6a..5eab92f6f 100644 --- a/hw/xfree86/xf4bpp/Makefile.am +++ b/hw/xfree86/xf4bpp/Makefile.am @@ -20,7 +20,6 @@ libxf4bpp_la_SOURCES = \ ppcPixmap.c \ ppcPntWin.c \ ppcPolyPnt.c \ - ppcPolyRec.c \ ppcQuery.c \ ppcRslvC.c \ ppcSetSp.c \ diff --git a/hw/xfree86/xf4bpp/offscreen.c b/hw/xfree86/xf4bpp/offscreen.c index f35bde7dd..654be829d 100644 --- a/hw/xfree86/xf4bpp/offscreen.c +++ b/hw/xfree86/xf4bpp/offscreen.c @@ -301,25 +301,6 @@ DoMono } void -xf4bppOffDrawMonoImage( pWin, data, x, y, w, h, fg, alu, planes ) -WindowPtr pWin; /* GJA */ -unsigned char *data; -int x, y, w, h ; -unsigned long int fg ; -int alu ; -unsigned long int planes; -{ - - if ( ( alu == GXnoop ) || !( planes &= VGA_ALLPLANES ) ) - return ; - - DoMono( pWin, w, x, y, (const unsigned char *) data, h, - w, ( ( w + 31 ) & ~31 ) >> 3, h, 0, 0, alu, - (int)planes, (int)fg) ; - -} - -void xf4bppOffFillStipple( pWin, pStipple, fg, alu, planes, x, y, w, h, xSrc, ySrc ) WindowPtr pWin; /* GJA */ register PixmapPtr const pStipple ; diff --git a/hw/xfree86/xf4bpp/ppcGC.c b/hw/xfree86/xf4bpp/ppcGC.c index 8153051f0..81441efd7 100644 --- a/hw/xfree86/xf4bpp/ppcGC.c +++ b/hw/xfree86/xf4bpp/ppcGC.c @@ -90,10 +90,9 @@ SOFTWARE. | GCFunction | GCPlaneMask | GCFillStyle | GC_CALL_VALIDATE_BIT \ | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode ) +static void xf4bppValidateGC(GCPtr, unsigned long, DrawablePtr); +static void xf4bppDestroyGC(GC *); -/* GJA -- we modified the following function to get rid of - * the records in file vgaData.c - */ static GCFuncs vgaGCFuncs = { xf4bppValidateGC, (void (*)(GCPtr, unsigned long))NoopDDA, @@ -196,7 +195,7 @@ register GCPtr pGC ; return TRUE ; } -void +static void xf4bppDestroyGC( pGC ) register GC *pGC ; @@ -292,7 +291,7 @@ return 0 ; CT_other ==> pCompositeClip is the pixmap bounding box */ -void +static void xf4bppValidateGC( pGC, changes, pDrawable ) GCPtr pGC; unsigned long changes; diff --git a/hw/xfree86/xf4bpp/ppcPixmap.c b/hw/xfree86/xf4bpp/ppcPixmap.c index 9f4cdc99a..9b2defda1 100644 --- a/hw/xfree86/xf4bpp/ppcPixmap.c +++ b/hw/xfree86/xf4bpp/ppcPixmap.c @@ -120,12 +120,8 @@ xf4bppCreatePixmap( pScreen, width, height, depth ) pPixmap->devKind = size; pPixmap->refcnt = 1 ; size = height * pPixmap->devKind ; -#ifdef PIXPRIV pPixmap->devPrivate.ptr = (pointer) (((CARD8*)pPixmap) + pScreen->totalPixmapSize); -#else - pPixmap->devPrivate.ptr = (pointer) (pPixmap + 1); -#endif bzero( (char *) pPixmap->devPrivate.ptr, size ) ; return pPixmap ; } diff --git a/hw/xfree86/xf4bpp/ppcPolyRec.c b/hw/xfree86/xf4bpp/ppcPolyRec.c deleted file mode 100644 index d7f866232..000000000 --- a/hw/xfree86/xf4bpp/ppcPolyRec.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright IBM Corporation 1987,1988,1989 - * - * All Rights Reserved - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * 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 IBM not be - * used in advertising or publicity pertaining to distribution of the - * software without specific, written prior permission. - * - * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING - * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL - * IBM 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. - * -*/ -/*********************************************************** - -Copyright (c) 1987 X Consortium - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of the X Consortium shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. - - -Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. - - All Rights Reserved - -Permission to use, copy, modify, and distribute this software and its -documentation for any purpose and without fee is hereby granted, -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 Digital not be -used in advertising or publicity pertaining to distribution of the -software without specific, written prior permission. - -DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING -ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL -DIGITAL 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. - -******************************************************************/ -/* $XConsortium: ppcPolyRec.c /main/4 1996/02/21 17:58:11 kaleb $ */ - -#ifdef HAVE_XORG_CONFIG_H -#include <xorg-config.h> -#endif - -#include "xf4bpp.h" - -void -xf4bppPolyRectangle(pDraw, pGC, nrects, pRects) - DrawablePtr pDraw; - GCPtr pGC; - int nrects; - xRectangle *pRects; -{ - int i; - xRectangle *pR = pRects; - xRectangle *tmprects, *tmprectsinit; - int lw, fs, ss; - - if ( ! ( tmprectsinit = tmprects = (xRectangle *)ALLOCATE_LOCAL( ( sizeof ( xRectangle ) * nrects ) << 2 ) ) ) - return; - - lw = pGC->lineWidth; - ss = lw >> 1; /* skinny side of line */ - fs = ( lw + 1 ) >> 1; /* fat side of line */ - - for (i=0; i<nrects; i++) - { - tmprects->x = pR->x - ss; - tmprects->y = pR->y - ss; - tmprects->width = pR->width + lw; - tmprects->height = lw; - tmprects++; - - tmprects->x = pR->x - ss; - tmprects->y = pR->y + fs; - tmprects->width = lw; - tmprects->height = pR->height - lw; - tmprects++; - - tmprects->x = pR->x + pR->width - ss; - tmprects->y = pR->y + fs; - tmprects->width = lw; - tmprects->height = pR->height - lw; - tmprects++; - - tmprects->x = pR->x - ss; - tmprects->y = pR->y + pR->height - ss; - tmprects->width = pR->width + lw; - tmprects->height = lw; - tmprects++; - - pR++; - } - - (* pGC->ops->PolyFillRect)( pDraw, pGC, nrects << 2, tmprectsinit ); - - DEALLOCATE_LOCAL( tmprectsinit ); - return ; -} diff --git a/hw/xfree86/xf4bpp/xf4bpp.h b/hw/xfree86/xf4bpp/xf4bpp.h index 8d2da35a5..01512a8fb 100644 --- a/hw/xfree86/xf4bpp/xf4bpp.h +++ b/hw/xfree86/xf4bpp/xf4bpp.h @@ -149,14 +149,6 @@ void xf4bppTilePixmapFS( Bool xf4bppCreateGC( GCPtr ); -void xf4bppDestroyGC( - GC * -); -void xf4bppValidateGC( - GCPtr, - unsigned long, - DrawablePtr -); /* ppcGetSp.c */ void xf4bppGetSpans( |