aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-08-01 09:13:47 +0200
committermarha <marha@users.sourceforge.net>2011-08-01 09:13:47 +0200
commit6730a76afc49a80573b2e582085086c2956fe96d (patch)
tree1478eb4f497670caeb2af983eadc4aee20f48b68 /xorg-server/hw
parenta69cff9373daf6b7afc97fb975ceb4fc0d6864f7 (diff)
parentf87ad0cdc41af88f134475ab50b0d604004d9cdc (diff)
downloadvcxsrv-6730a76afc49a80573b2e582085086c2956fe96d.tar.gz
vcxsrv-6730a76afc49a80573b2e582085086c2956fe96d.tar.bz2
vcxsrv-6730a76afc49a80573b2e582085086c2956fe96d.zip
Merge remote-tracking branch 'origin/released'
Conflicts: mesalib/src/glsl/ast_function.cpp mesalib/src/glsl/glsl_types.cpp mesalib/src/mesa/main/teximage.c mesalib/src/mesa/main/texparam.c xorg-server/config/udev.c xorg-server/configure.ac xorg-server/dix/main.c xorg-server/hw/dmx/dmxinit.c xorg-server/hw/kdrive/src/kdrive.c xorg-server/hw/xfree86/common/xf86Config.c xorg-server/hw/xfree86/common/xf86Configure.c xorg-server/hw/xfree86/common/xf86Helper.c xorg-server/hw/xfree86/common/xf86Init.c xorg-server/hw/xfree86/common/xf86Option.c xorg-server/hw/xfree86/common/xf86Priv.h xorg-server/hw/xfree86/common/xf86Xinput.c xorg-server/hw/xnest/Init.c xorg-server/hw/xquartz/darwin.c xorg-server/hw/xwin/InitOutput.c xorg-server/hw/xwin/winerror.c xorg-server/hw/xwin/xlaunch/config.cc xorg-server/hw/xwin/xlaunch/config.h xorg-server/hw/xwin/xlaunch/main.cc xorg-server/hw/xwin/xlaunch/resources/dialog.rc xorg-server/hw/xwin/xlaunch/resources/resources.h xorg-server/hw/xwin/xlaunch/resources/resources.rc xorg-server/hw/xwin/xlaunch/resources/strings.rc xorg-server/hw/xwin/xlaunch/window/util.cc xorg-server/hw/xwin/xlaunch/window/util.h xorg-server/hw/xwin/xlaunch/window/wizard.h xorg-server/include/os.h xorg-server/os/log.c xorg-server/xkeyboard-config/symbols/lv
Diffstat (limited to 'xorg-server/hw')
-rw-r--r--xorg-server/hw/dmx/dmxinit.c2058
-rw-r--r--xorg-server/hw/kdrive/src/kdrive.c6
-rw-r--r--xorg-server/hw/vfb/InitOutput.c1938
-rw-r--r--xorg-server/hw/xfree86/common/xf86Config.c3
-rw-r--r--xorg-server/hw/xfree86/common/xf86Configure.c2
-rw-r--r--xorg-server/hw/xfree86/common/xf86Helper.c4
-rw-r--r--xorg-server/hw/xfree86/common/xf86Init.c40
-rw-r--r--xorg-server/hw/xfree86/common/xf86Option.c2
-rw-r--r--xorg-server/hw/xfree86/common/xf86Priv.h2
-rw-r--r--xorg-server/hw/xfree86/common/xf86ShowOpts.c260
-rw-r--r--xorg-server/hw/xfree86/common/xf86Xinput.c1
-rw-r--r--xorg-server/hw/xnest/Init.c6
-rw-r--r--xorg-server/hw/xquartz/darwin.c6
-rw-r--r--xorg-server/hw/xwin/InitOutput.c10
-rw-r--r--xorg-server/hw/xwin/Makefile.am22
-rw-r--r--xorg-server/hw/xwin/winerror.c334
16 files changed, 2350 insertions, 2344 deletions
diff --git a/xorg-server/hw/dmx/dmxinit.c b/xorg-server/hw/dmx/dmxinit.c
index 5dce93028..a8399bc75 100644
--- a/xorg-server/hw/dmx/dmxinit.c
+++ b/xorg-server/hw/dmx/dmxinit.c
@@ -1,1029 +1,1029 @@
-/*
- * Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
- *
- * 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 on 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
- * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
- * 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:
- * Kevin E. Martin <kem@redhat.com>
- * David H. Dawes <dawes@xfree86.org>
- * Rickard E. (Rik) Faith <faith@redhat.com>
- *
- */
-
-/** \file
- * Provide expected functions for initialization from the ddx layer and
- * global variables for the DMX server. */
-
-#ifdef HAVE_DMX_CONFIG_H
-#include <dmx-config.h>
-#endif
-
-#include "dmx.h"
-#include "dmxinit.h"
-#include "dmxsync.h"
-#include "dmxlog.h"
-#include "dmxinput.h"
-#include "dmxscrinit.h"
-#include "dmxcursor.h"
-#include "dmxfont.h"
-#include "config/dmxconfig.h"
-#include "dmxcb.h"
-#include "dmxprop.h"
-#include "dmxstat.h"
-#include "dmxpict.h"
-
-#include <X11/Xos.h> /* For gettimeofday */
-#include "dixstruct.h"
-#ifdef PANORAMIX
-#include "panoramiXsrv.h"
-#endif
-
-#include <signal.h> /* For SIGQUIT */
-
-#ifdef GLXEXT
-#include <GL/glx.h>
-#include <GL/glxint.h>
-#include "dmx_glxvisuals.h"
-#include <X11/extensions/Xext.h>
-#include <X11/extensions/extutil.h>
-#endif /* GLXEXT */
-
-/* Global variables available to all Xserver/hw/dmx routines. */
-int dmxNumScreens;
-DMXScreenInfo *dmxScreens;
-
-int dmxNumInputs;
-DMXInputInfo *dmxInputs;
-
-int dmxShadowFB = FALSE;
-
-XErrorEvent dmxLastErrorEvent;
-Bool dmxErrorOccurred = FALSE;
-
-char *dmxFontPath = NULL;
-
-Bool dmxOffScreenOpt = TRUE;
-
-Bool dmxSubdividePrimitives = TRUE;
-
-Bool dmxLazyWindowCreation = TRUE;
-
-Bool dmxUseXKB = TRUE;
-
-int dmxDepth = 0;
-
-#ifndef GLXEXT
-static Bool dmxGLXProxy = FALSE;
-#else
-Bool dmxGLXProxy = TRUE;
-
-Bool dmxGLXSwapGroupSupport = TRUE;
-
-Bool dmxGLXSyncSwap = FALSE;
-
-Bool dmxGLXFinishSwap = FALSE;
-#endif
-
-Bool dmxIgnoreBadFontPaths = FALSE;
-
-Bool dmxAddRemoveScreens = FALSE;
-
-/* dmxErrorHandler catches errors that occur when calling one of the
- * back-end servers. Some of this code is based on _XPrintDefaultError
- * in xc/lib/X11/XlibInt.c */
-static int dmxErrorHandler(Display *dpy, XErrorEvent *ev)
-{
-#define DMX_ERROR_BUF_SIZE 256
- /* RATS: these buffers are only used in
- * length-limited calls. */
- char buf[DMX_ERROR_BUF_SIZE];
- char request[DMX_ERROR_BUF_SIZE];
- _XExtension *ext = NULL;
-
- dmxErrorOccurred = TRUE;
- dmxLastErrorEvent = *ev;
-
- XGetErrorText(dpy, ev->error_code, buf, sizeof(buf));
- dmxLog(dmxWarning, "dmxErrorHandler: %s\n", buf);
-
- /* Find major opcode name */
- if (ev->request_code < 128) {
- XmuSnprintf(request, sizeof(request), "%d", ev->request_code);
- XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf));
- } else {
- for (ext = dpy->ext_procs;
- ext && ext->codes.major_opcode != ev->request_code;
- ext = ext->next);
- if (ext) strncpy(buf, ext->name, sizeof(buf));
- else buf[0] = '\0';
- }
- dmxLog(dmxWarning, " Major opcode: %d (%s)\n",
- ev->request_code, buf);
-
- /* Find minor opcode name */
- if (ev->request_code >= 128 && ext) {
- XmuSnprintf(request, sizeof(request), "%d", ev->request_code);
- XmuSnprintf(request, sizeof(request), "%s.%d",
- ext->name, ev->minor_code);
- XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf));
- dmxLog(dmxWarning, " Minor opcode: %d (%s)\n",
- ev->minor_code, buf);
- }
-
- /* Provide value information */
- switch (ev->error_code) {
- case BadValue:
- dmxLog(dmxWarning, " Value: 0x%x\n",
- ev->resourceid);
- break;
- case BadAtom:
- dmxLog(dmxWarning, " AtomID: 0x%x\n",
- ev->resourceid);
- break;
- default:
- dmxLog(dmxWarning, " ResourceID: 0x%x\n",
- ev->resourceid);
- break;
- }
-
- /* Provide serial number information */
- dmxLog(dmxWarning, " Failed serial number: %d\n",
- ev->serial);
- dmxLog(dmxWarning, " Current serial number: %d\n",
- dpy->request);
- return 0;
-}
-
-#ifdef GLXEXT
-static int dmxNOPErrorHandler(Display *dpy, XErrorEvent *ev)
-{
- return 0;
-}
-#endif
-
-Bool dmxOpenDisplay(DMXScreenInfo *dmxScreen)
-{
- if (!(dmxScreen->beDisplay = XOpenDisplay(dmxScreen->name)))
- return FALSE;
-
- dmxPropertyDisplay(dmxScreen);
- return TRUE;
-}
-
-void dmxSetErrorHandler(DMXScreenInfo *dmxScreen)
-{
- XSetErrorHandler(dmxErrorHandler);
-}
-
-static void dmxPrintScreenInfo(DMXScreenInfo *dmxScreen)
-{
- XWindowAttributes attribs;
- int ndepths = 0, *depths = NULL;
- int i;
- Display *dpy = dmxScreen->beDisplay;
- Screen *s = DefaultScreenOfDisplay(dpy);
- int scr = DefaultScreen(dpy);
-
- XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &attribs);
- if (!(depths = XListDepths(dpy, scr, &ndepths))) ndepths = 0;
-
- dmxLogOutput(dmxScreen, "Name of display: %s\n", DisplayString(dpy));
- dmxLogOutput(dmxScreen, "Version number: %d.%d\n",
- ProtocolVersion(dpy), ProtocolRevision(dpy));
- dmxLogOutput(dmxScreen, "Vendor string: %s\n", ServerVendor(dpy));
- if (!strstr(ServerVendor(dpy), "XFree86")) {
- dmxLogOutput(dmxScreen, "Vendor release: %d\n", VendorRelease(dpy));
- } else {
- /* This code based on xdpyinfo.c */
- int v = VendorRelease(dpy);
- int major = -1, minor = -1, patch = -1, subpatch = -1;
-
- if (v < 336)
- major = v / 100, minor = (v / 10) % 10, patch = v % 10;
- else if (v < 3900) {
- major = v / 1000;
- minor = (v / 100) % 10;
- if (((v / 10) % 10) || (v % 10)) {
- patch = (v / 10) % 10;
- if (v % 10) subpatch = v % 10;
- }
- } else if (v < 40000000) {
- major = v / 1000;
- minor = (v / 10) % 10;
- if (v % 10) patch = v % 10;
- } else {
- major = v / 10000000;
- minor = (v / 100000) % 100;
- patch = (v / 1000) % 100;
- if (v % 1000) subpatch = v % 1000;
- }
- dmxLogOutput(dmxScreen, "Vendor release: %d (XFree86 version: %d.%d",
- v, major, minor);
- if (patch > 0) dmxLogOutputCont(dmxScreen, ".%d", patch);
- if (subpatch > 0) dmxLogOutputCont(dmxScreen, ".%d", subpatch);
- dmxLogOutputCont(dmxScreen, ")\n");
- }
-
-
- dmxLogOutput(dmxScreen, "Dimensions: %dx%d pixels\n",
- attribs.width, attribs.height);
- dmxLogOutput(dmxScreen, "%d depths on screen %d: ", ndepths, scr);
- for (i = 0; i < ndepths; i++)
- dmxLogOutputCont(dmxScreen, "%c%d", i ? ',' : ' ', depths[i]);
- dmxLogOutputCont(dmxScreen, "\n");
- dmxLogOutput(dmxScreen, "Depth of root window: %d plane%s (%d)\n",
- attribs.depth, attribs.depth == 1 ? "" : "s",
- DisplayPlanes(dpy, scr));
- dmxLogOutput(dmxScreen, "Number of colormaps: %d min, %d max\n",
- MinCmapsOfScreen(s), MaxCmapsOfScreen(s));
- dmxLogOutput(dmxScreen, "Options: backing-store %s, save-unders %s\n",
- (DoesBackingStore (s) == NotUseful) ? "no" :
- ((DoesBackingStore (s) == Always) ? "yes" : "when mapped"),
- DoesSaveUnders (s) ? "yes" : "no");
- dmxLogOutput(dmxScreen, "Window Manager running: %s\n",
- (dmxScreen->WMRunningOnBE) ? "yes" : "no");
-
- if (dmxScreen->WMRunningOnBE) {
- dmxLogOutputWarning(dmxScreen,
- "Window manager running "
- "-- colormaps not supported\n");
- }
- XFree(depths);
-}
-
-void dmxGetScreenAttribs(DMXScreenInfo *dmxScreen)
-{
- XWindowAttributes attribs;
- Display *dpy = dmxScreen->beDisplay;
-#ifdef GLXEXT
- int dummy;
-#endif
-
- XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &attribs);
-
- dmxScreen->beWidth = attribs.width;
- dmxScreen->beHeight = attribs.height;
-
- /* Fill in missing geometry information */
- if (dmxScreen->scrnXSign < 0) {
- if (dmxScreen->scrnWidth) {
- dmxScreen->scrnX = (attribs.width - dmxScreen->scrnWidth
- - dmxScreen->scrnX);
- } else {
- dmxScreen->scrnWidth = attribs.width - dmxScreen->scrnX;
- dmxScreen->scrnX = 0;
- }
- }
- if (dmxScreen->scrnYSign < 0) {
- if (dmxScreen->scrnHeight) {
- dmxScreen->scrnY = (attribs.height - dmxScreen->scrnHeight
- - dmxScreen->scrnY);
- } else {
- dmxScreen->scrnHeight = attribs.height - dmxScreen->scrnY;
- dmxScreen->scrnY = 0;
- }
- }
- if (!dmxScreen->scrnWidth)
- dmxScreen->scrnWidth = attribs.width - dmxScreen->scrnX;
- if (!dmxScreen->scrnHeight)
- dmxScreen->scrnHeight = attribs.height - dmxScreen->scrnY;
-
- if (!dmxScreen->rootWidth) dmxScreen->rootWidth = dmxScreen->scrnWidth;
- if (!dmxScreen->rootHeight) dmxScreen->rootHeight = dmxScreen->scrnHeight;
- if (dmxScreen->rootWidth + dmxScreen->rootX > dmxScreen->scrnWidth)
- dmxScreen->rootWidth = dmxScreen->scrnWidth - dmxScreen->rootX;
- if (dmxScreen->rootHeight + dmxScreen->rootY > dmxScreen->scrnHeight)
- dmxScreen->rootHeight = dmxScreen->scrnHeight - dmxScreen->rootY;
-
- /* FIXME: Get these from the back-end server */
- dmxScreen->beXDPI = 75;
- dmxScreen->beYDPI = 75;
-
- dmxScreen->beDepth = attribs.depth; /* FIXME: verify that this
- * works always. In
- * particular, this will work
- * well for depth=16, will fail
- * because of colormap issues
- * at depth 8. More work needs
- * to be done here. */
-
- if (dmxScreen->beDepth <= 8) dmxScreen->beBPP = 8;
- else if (dmxScreen->beDepth <= 16) dmxScreen->beBPP = 16;
- else dmxScreen->beBPP = 32;
-
-#ifdef GLXEXT
- /* get the majorOpcode for the back-end GLX extension */
- XQueryExtension(dpy, "GLX", &dmxScreen->glxMajorOpcode,
- &dummy, &dmxScreen->glxErrorBase);
-#endif
-
- dmxPrintScreenInfo(dmxScreen);
- dmxLogOutput(dmxScreen, "%dx%d+%d+%d on %dx%d at depth=%d, bpp=%d\n",
- dmxScreen->scrnWidth, dmxScreen->scrnHeight,
- dmxScreen->scrnX, dmxScreen->scrnY,
- dmxScreen->beWidth, dmxScreen->beHeight,
- dmxScreen->beDepth, dmxScreen->beBPP);
- if (dmxScreen->beDepth == 8)
- dmxLogOutputWarning(dmxScreen,
- "Support for depth == 8 is not complete\n");
-}
-
-Bool dmxGetVisualInfo(DMXScreenInfo *dmxScreen)
-{
- int i;
- XVisualInfo visinfo;
-
- visinfo.screen = DefaultScreen(dmxScreen->beDisplay);
- dmxScreen->beVisuals = XGetVisualInfo(dmxScreen->beDisplay,
- VisualScreenMask,
- &visinfo,
- &dmxScreen->beNumVisuals);
-
- dmxScreen->beDefVisualIndex = -1;
-
- if (defaultColorVisualClass >= 0 || dmxDepth > 0) {
- for (i = 0; i < dmxScreen->beNumVisuals; i++)
- if (defaultColorVisualClass >= 0) {
- if (dmxScreen->beVisuals[i].class == defaultColorVisualClass) {
- if (dmxDepth > 0) {
- if (dmxScreen->beVisuals[i].depth == dmxDepth) {
- dmxScreen->beDefVisualIndex = i;
- break;
- }
- } else {
- dmxScreen->beDefVisualIndex = i;
- break;
- }
- }
- } else if (dmxScreen->beVisuals[i].depth == dmxDepth) {
- dmxScreen->beDefVisualIndex = i;
- break;
- }
- } else {
- visinfo.visualid =
- XVisualIDFromVisual(DefaultVisual(dmxScreen->beDisplay,
- visinfo.screen));
-
- for (i = 0; i < dmxScreen->beNumVisuals; i++)
- if (visinfo.visualid == dmxScreen->beVisuals[i].visualid) {
- dmxScreen->beDefVisualIndex = i;
- break;
- }
- }
-
- for (i = 0; i < dmxScreen->beNumVisuals; i++)
- dmxLogVisual(dmxScreen, &dmxScreen->beVisuals[i],
- (i == dmxScreen->beDefVisualIndex));
-
- return dmxScreen->beDefVisualIndex >= 0;
-}
-
-void dmxGetColormaps(DMXScreenInfo *dmxScreen)
-{
- int i;
-
- dmxScreen->beNumDefColormaps = dmxScreen->beNumVisuals;
- dmxScreen->beDefColormaps = malloc(dmxScreen->beNumDefColormaps *
- sizeof(*dmxScreen->beDefColormaps));
-
- for (i = 0; i < dmxScreen->beNumDefColormaps; i++)
- dmxScreen->beDefColormaps[i] =
- XCreateColormap(dmxScreen->beDisplay,
- DefaultRootWindow(dmxScreen->beDisplay),
- dmxScreen->beVisuals[i].visual,
- AllocNone);
-
- dmxScreen->beBlackPixel = BlackPixel(dmxScreen->beDisplay,
- DefaultScreen(dmxScreen->beDisplay));
- dmxScreen->beWhitePixel = WhitePixel(dmxScreen->beDisplay,
- DefaultScreen(dmxScreen->beDisplay));
-}
-
-void dmxGetPixmapFormats(DMXScreenInfo *dmxScreen)
-{
- dmxScreen->beDepths =
- XListDepths(dmxScreen->beDisplay, DefaultScreen(dmxScreen->beDisplay),
- &dmxScreen->beNumDepths);
-
- dmxScreen->bePixmapFormats =
- XListPixmapFormats(dmxScreen->beDisplay,
- &dmxScreen->beNumPixmapFormats);
-}
-
-static Bool dmxSetPixmapFormats(ScreenInfo *pScreenInfo,
- DMXScreenInfo *dmxScreen)
-{
- XPixmapFormatValues *bePixmapFormat;
- PixmapFormatRec *format;
- int i, j;
-
- pScreenInfo->imageByteOrder = ImageByteOrder(dmxScreen->beDisplay);
- pScreenInfo->bitmapScanlineUnit = BitmapUnit(dmxScreen->beDisplay);
- pScreenInfo->bitmapScanlinePad = BitmapPad(dmxScreen->beDisplay);
- pScreenInfo->bitmapBitOrder = BitmapBitOrder(dmxScreen->beDisplay);
-
- pScreenInfo->numPixmapFormats = 0;
- for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
- bePixmapFormat = &dmxScreen->bePixmapFormats[i];
- for (j = 0; j < dmxScreen->beNumDepths; j++)
- if ((bePixmapFormat->depth == 1) ||
- (bePixmapFormat->depth == dmxScreen->beDepths[j])) {
- format = &pScreenInfo->formats[pScreenInfo->numPixmapFormats];
-
- format->depth = bePixmapFormat->depth;
- format->bitsPerPixel = bePixmapFormat->bits_per_pixel;
- format->scanlinePad = bePixmapFormat->scanline_pad;
-
- pScreenInfo->numPixmapFormats++;
- break;
- }
- }
-
- return TRUE;
-}
-
-void dmxCheckForWM(DMXScreenInfo *dmxScreen)
-{
- Status status;
- XWindowAttributes xwa;
-
- status = XGetWindowAttributes(dmxScreen->beDisplay,
- DefaultRootWindow(dmxScreen->beDisplay),
- &xwa);
- dmxScreen->WMRunningOnBE =
- (status &&
- ((xwa.all_event_masks & SubstructureRedirectMask) ||
- (xwa.all_event_masks & SubstructureNotifyMask)));
-}
-
-/** Initialize the display and collect relevant information about the
- * display properties */
-static void dmxDisplayInit(DMXScreenInfo *dmxScreen)
-{
- if (!dmxOpenDisplay(dmxScreen))
- dmxLog(dmxFatal,
- "dmxOpenDisplay: Unable to open display %s\n",
- dmxScreen->name);
-
- dmxSetErrorHandler(dmxScreen);
- dmxCheckForWM(dmxScreen);
- dmxGetScreenAttribs(dmxScreen);
-
- if (!dmxGetVisualInfo(dmxScreen))
- dmxLog(dmxFatal, "dmxGetVisualInfo: No matching visuals found\n");
-
- dmxGetColormaps(dmxScreen);
- dmxGetPixmapFormats(dmxScreen);
-}
-
-/* If this doesn't compile, just add || defined(yoursystem) to the line
- * below. This information is to help with bug reports and is not
- * critical. */
-#if !defined(_POSIX_SOURCE)
-static const char *dmxExecOS(void) { return ""; }
-#else
-#include <sys/utsname.h>
-static const char *dmxExecOS(void)
-{
- static char buffer[128];
- static int initialized = 0;
- struct utsname u;
-
- if (!initialized++) {
- memset(buffer, 0, sizeof(buffer));
- uname(&u);
- XmuSnprintf(buffer, sizeof(buffer)-1, "%s %s %s",
- u.sysname, u.release, u.version);
- }
- return buffer;
-}
-#endif
-
-static const char *dmxBuildCompiler(void)
-{
- static char buffer[128];
- static int initialized = 0;
-
- if (!initialized++) {
- memset(buffer, 0, sizeof(buffer));
-#if defined(__GNUC__) && defined(__GNUC_MINOR__) &&defined(__GNUC_PATCHLEVEL__)
- XmuSnprintf(buffer, sizeof(buffer)-1, "gcc %d.%d.%d",
- __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
-#endif
- }
- return buffer;
-}
-
-static const char *dmxExecHost(void)
-{
- static char buffer[128];
- static int initialized = 0;
-
- if (!initialized++) {
- memset(buffer, 0, sizeof(buffer));
- XmuGetHostname(buffer, sizeof(buffer) - 1);
- }
- return buffer;
-}
-
-/** This routine is called in Xserver/dix/main.c from \a main(). */
-void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[])
-{
- int i;
- static unsigned long dmxGeneration = 0;
-#ifdef GLXEXT
- Bool glxSupported = TRUE;
-#endif
-
- if (dmxGeneration != serverGeneration) {
- int vendrel = VENDOR_RELEASE;
- int major, minor, year, month, day;
-
- dmxGeneration = serverGeneration;
-
- major = vendrel / 100000000;
- vendrel -= major * 100000000;
- minor = vendrel / 1000000;
- vendrel -= minor * 1000000;
- year = vendrel / 10000;
- vendrel -= year * 10000;
- month = vendrel / 100;
- vendrel -= month * 100;
- day = vendrel;
-
- /* Add other epoch tests here */
- if (major > 0 && minor > 0) year += 2000;
-
- dmxLog(dmxInfo, "Generation: %d\n", dmxGeneration);
- dmxLog(dmxInfo, "DMX version: %d.%d.%02d%02d%02d (%s)\n",
- major, minor, year, month, day, VENDOR_STRING);
-
- SetVendorRelease(VENDOR_RELEASE);
- SetVendorString(VENDOR_STRING);
-
- if (dmxGeneration == 1) {
- dmxLog(dmxInfo, "DMX Build OS: %s (%s)\n", OSNAME, OSVENDOR);
- dmxLog(dmxInfo, "DMX Build Compiler: %s\n", dmxBuildCompiler());
- dmxLog(dmxInfo, "DMX Execution OS: %s\n", dmxExecOS());
- dmxLog(dmxInfo, "DMX Execution Host: %s\n", dmxExecHost());
- }
- dmxLog(dmxInfo, "MAXSCREENS: %d\n", MAXSCREENS);
-
- for (i = 0; i < dmxNumScreens; i++) {
- if (dmxScreens[i].beDisplay)
- dmxLog(dmxWarning, "Display \"%s\" still open\n",
- dmxScreens[i].name);
- dmxStatFree(dmxScreens[i].stat);
- dmxScreens[i].stat = NULL;
- }
- for (i = 0; i < dmxNumInputs; i++) dmxInputFree(&dmxInputs[i]);
- free(dmxScreens);
- free(dmxInputs);
- dmxScreens = NULL;
- dmxInputs = NULL;
- dmxNumScreens = 0;
- dmxNumInputs = 0;
- }
-
- /* Make sure that the command-line arguments are sane. */
- if (dmxAddRemoveScreens && dmxGLXProxy) {
- /* Currently it is not possible to support GLX and Render
- * extensions with dynamic screen addition/removal due to the
- * state that each extension keeps, which cannot be restored. */
- dmxLog(dmxWarning,
- "GLX Proxy and Render extensions do not yet support dynamic\n");
- dmxLog(dmxWarning,
- "screen addition and removal. Please specify -noglxproxy\n");
- dmxLog(dmxWarning,
- "and -norender on the command line or in the configuration\n");
- dmxLog(dmxWarning,
- "file to disable these two extensions if you wish to use\n");
- dmxLog(dmxWarning,
- "the dynamic addition and removal of screens support.\n");
- dmxLog(dmxFatal,
- "Dynamic screen addition/removal error (see above).\n");
- }
-
- /* ddxProcessArgument has been called at this point, but any data
- * from the configuration file has not been applied. Do so, and be
- * sure we have at least one back-end display. */
- dmxConfigConfigure();
- if (!dmxNumScreens)
- dmxLog(dmxFatal, "InitOutput: no back-end displays found\n");
- if (!dmxNumInputs)
- dmxLog(dmxInfo, "InitOutput: no inputs found\n");
-
- /* Disable lazy window creation optimization if offscreen
- * optimization is disabled */
- if (!dmxOffScreenOpt && dmxLazyWindowCreation) {
- dmxLog(dmxInfo,
- "InitOutput: Disabling lazy window creation optimization\n");
- dmxLog(dmxInfo,
- " since it requires the offscreen optimization\n");
- dmxLog(dmxInfo,
- " to function properly.\n");
- dmxLazyWindowCreation = FALSE;
- }
-
- /* Open each display and gather information about it. */
- for (i = 0; i < dmxNumScreens; i++)
- dmxDisplayInit(&dmxScreens[i]);
-
-#if PANORAMIX
- /* Register a Xinerama callback which will run from within
- * PanoramiXCreateConnectionBlock. We can use the callback to
- * determine if Xinerama is loaded and to check the visuals
- * determined by PanoramiXConsolidate. */
- XineramaRegisterConnectionBlockCallback(dmxConnectionBlockCallback);
-#endif
-
- /* Since we only have a single screen thus far, we only need to set
- the pixmap formats to match that screen. FIXME: this isn't true.*/
- if (!dmxSetPixmapFormats(pScreenInfo, &dmxScreens[0])) return;
-
- /* Might want to install a signal handler to allow cleaning up after
- * unexpected signals. The DIX/OS layer already handles SIGINT and
- * SIGTERM, so everything is OK for expected signals. --DD
- *
- * SIGHUP, SIGINT, and SIGTERM are trapped in os/connection.c
- * SIGQUIT is another common signal that is sent from the keyboard.
- * Trap it here, to ensure that the keyboard modifier map and other
- * state for the input devices are restored. (This makes the
- * behavior of SIGQUIT somewhat unexpected, since it will be the
- * same as the behavior of SIGINT. However, leaving the modifier
- * map of the input devices empty is even more unexpected.) --RF
- */
- OsSignal(SIGQUIT, GiveUp);
-
-#ifdef GLXEXT
- /* Check if GLX extension exists on all back-end servers */
- for (i = 0; i < dmxNumScreens; i++)
- glxSupported &= (dmxScreens[i].glxMajorOpcode > 0);
-#endif
-
- /* Tell dix layer about the backend displays */
- for (i = 0; i < dmxNumScreens; i++) {
-
-#ifdef GLXEXT
- if (glxSupported) {
- /*
- * Builds GLX configurations from the list of visuals
- * supported by the back-end server, and give that
- * configuration list to the glx layer - so that he will
- * build the visuals accordingly.
- */
-
- DMXScreenInfo *dmxScreen = &dmxScreens[i];
- __GLXvisualConfig *configs = NULL;
- dmxGlxVisualPrivate **configprivs = NULL;
- int nconfigs = 0;
- int (*oldErrorHandler)(Display *, XErrorEvent *);
- int i;
-
- /* Catch errors if when using an older GLX w/o FBconfigs */
- oldErrorHandler = XSetErrorHandler(dmxNOPErrorHandler);
-
- /* Get FBConfigs of the back-end server */
- dmxScreen->fbconfigs = GetGLXFBConfigs(dmxScreen->beDisplay,
- dmxScreen->glxMajorOpcode,
- &dmxScreen->numFBConfigs);
-
- XSetErrorHandler(oldErrorHandler);
-
- dmxScreen->glxVisuals =
- GetGLXVisualConfigs(dmxScreen->beDisplay,
- DefaultScreen(dmxScreen->beDisplay),
- &dmxScreen->numGlxVisuals);
-
- if (dmxScreen->fbconfigs) {
- configs =
- GetGLXVisualConfigsFromFBConfigs(dmxScreen->fbconfigs,
- dmxScreen->numFBConfigs,
- dmxScreen->beVisuals,
- dmxScreen->beNumVisuals,
- dmxScreen->glxVisuals,
- dmxScreen->numGlxVisuals,
- &nconfigs);
- } else {
- configs = dmxScreen->glxVisuals;
- nconfigs = dmxScreen->numGlxVisuals;
- }
-
- configprivs = malloc(nconfigs * sizeof(dmxGlxVisualPrivate*));
-
- if (configs != NULL && configprivs != NULL) {
-
- /* Initialize our private info for each visual
- * (currently only x_visual_depth and x_visual_class)
- */
- for (i = 0; i < nconfigs; i++) {
-
- configprivs[i] = (dmxGlxVisualPrivate *)
- malloc(sizeof(dmxGlxVisualPrivate));
- configprivs[i]->x_visual_depth = 0;
- configprivs[i]->x_visual_class = 0;
-
- /* Find the visual depth */
- if (configs[i].vid > 0) {
- int j;
- for (j = 0; j < dmxScreen->beNumVisuals; j++) {
- if (dmxScreen->beVisuals[j].visualid ==
- configs[i].vid) {
- configprivs[i]->x_visual_depth =
- dmxScreen->beVisuals[j].depth;
- configprivs[i]->x_visual_class =
- dmxScreen->beVisuals[j].class;
- break;
- }
- }
- }
- }
-
- XFlush(dmxScreen->beDisplay);
- }
- }
-#endif /* GLXEXT */
-
- AddScreen(dmxScreenInit, argc, argv);
- }
-
- /* Compute origin information. */
- dmxInitOrigins();
-
- /* Compute overlap information. */
- dmxInitOverlap();
-
- /* Make sure there is a global width/height available */
- dmxComputeWidthHeight(DMX_NO_RECOMPUTE_BOUNDING_BOX);
-
- /* FIXME: The following is temporarily placed here. When the DMX
- * extension is available, it will be move there.
- */
- dmxInitFonts();
-
- /* Initialize the render extension */
- if (!noRenderExtension)
- dmxInitRender();
-
- /* Initialized things that need timer hooks */
- dmxStatInit();
- dmxSyncInit(); /* Calls RegisterBlockAndWakeupHandlers */
-
- dmxLog(dmxInfo, "Shadow framebuffer support %s\n",
- dmxShadowFB ? "enabled" : "disabled");
-}
-
-/* RATS: Assuming the fp string (which comes from the command-line argv
- vector) is NULL-terminated, the buffer is large enough for the
- strcpy. */
-static void dmxSetDefaultFontPath(char *fp)
-{
- int fplen = strlen(fp) + 1;
-
- if (dmxFontPath) {
- int len;
-
- len = strlen(dmxFontPath);
- dmxFontPath = realloc(dmxFontPath, len+fplen+1);
- dmxFontPath[len] = ',';
- strncpy(&dmxFontPath[len+1], fp, fplen);
- } else {
- dmxFontPath = malloc(fplen);
- strncpy(dmxFontPath, fp, fplen);
- }
-
- defaultFontPath = dmxFontPath;
-}
-
-/** This function is called in Xserver/os/utils.c from \a AbortServer().
- * We must ensure that backend and console state is restored in the
- * event the server shutdown wasn't clean. */
-void AbortDDX(void)
-{
- int i;
-
- for (i=0; i < dmxNumScreens; i++) {
- DMXScreenInfo *dmxScreen = &dmxScreens[i];
-
- if (dmxScreen->beDisplay) XCloseDisplay(dmxScreen->beDisplay);
- dmxScreen->beDisplay = NULL;
- }
-}
-
-#ifdef DDXBEFORERESET
-/* This function is called in Xserver/dix/dispatch.c */
-void ddxBeforeReset(void)
-{
-}
-#endif
-
-/** This function is called in Xserver/dix/main.c from \a main() when
- * dispatchException & DE_TERMINATE (which is the only way to exit the
- * main loop without an interruption. */
-void ddxGiveUp(void)
-{
- AbortDDX();
-}
-
-/** This function is called in Xserver/os/osinit.c from \a OsInit(). */
-void OsVendorInit(void)
-{
-}
-
-/** This function is called in Xserver/os/utils.c from \a FatalError()
- * and \a VFatalError(). (Note that setting the function pointer \a
- * OsVendorVErrorFProc will cause \a VErrorF() (which is called by the
- * two routines mentioned here, as well as by others) to use the
- * referenced routine instead of \a vfprintf().) */
-void OsVendorFatalError(void)
-{
-}
-
-/** Process our command line arguments. */
-int ddxProcessArgument(int argc, char *argv[], int i)
-{
- int retval = 0;
-
- if (!strcmp(argv[i], "-display")) {
- if (++i < argc) dmxConfigStoreDisplay(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-inputfrom") || !strcmp(argv[i], "-input")) {
- if (++i < argc) dmxConfigStoreInput(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-xinputfrom") || !strcmp(argv[i],"-xinput")) {
- if (++i < argc) dmxConfigStoreXInput(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-noshadowfb")) {
- dmxLog(dmxWarning,
- "-noshadowfb has been deprecated "
- "since it is now the default\n");
- dmxShadowFB = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-nomulticursor")) {
- dmxCursorNoMulti();
- retval = 1;
- } else if (!strcmp(argv[i], "-shadowfb")) {
- dmxShadowFB = TRUE;
- retval = 1;
- } else if (!strcmp(argv[i], "-configfile")) {
- if (++i < argc) dmxConfigStoreFile(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-config")) {
- if (++i < argc) dmxConfigStoreConfig(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-fontpath")) {
- if (++i < argc) dmxSetDefaultFontPath(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-stat")) {
- if ((i += 2) < argc) dmxStatActivate(argv[i-1], argv[i]);
- retval = 3;
- } else if (!strcmp(argv[i], "-syncbatch")) {
- if (++i < argc) dmxSyncActivate(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-nooffscreenopt")) {
- dmxOffScreenOpt = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-nosubdivprims")) {
- dmxSubdividePrimitives = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-nowindowopt")) {
- dmxLazyWindowCreation = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-noxkb")) {
- dmxUseXKB = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-depth")) {
- if (++i < argc) dmxDepth = atoi(argv[i]);
- retval = 2;
- } else if (!strcmp(argv[i], "-norender")) {
- noRenderExtension = TRUE;
- retval = 1;
-#ifdef GLXEXT
- } else if (!strcmp(argv[i], "-noglxproxy")) {
- dmxGLXProxy = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-noglxswapgroup")) {
- dmxGLXSwapGroupSupport = FALSE;
- retval = 1;
- } else if (!strcmp(argv[i], "-glxsyncswap")) {
- dmxGLXSyncSwap = TRUE;
- retval = 1;
- } else if (!strcmp(argv[i], "-glxfinishswap")) {
- dmxGLXFinishSwap = TRUE;
- retval = 1;
-#endif
- } else if (!strcmp(argv[i], "-ignorebadfontpaths")) {
- dmxIgnoreBadFontPaths = TRUE;
- retval = 1;
- } else if (!strcmp(argv[i], "-addremovescreens")) {
- dmxAddRemoveScreens = TRUE;
- retval = 1;
- } else if (!strcmp(argv[i], "-param")) {
- if ((i += 2) < argc) {
- if (!strcasecmp(argv[i-1], "xkbrules"))
- dmxConfigSetXkbRules(argv[i]);
- else if (!strcasecmp(argv[i-1], "xkbmodel"))
- dmxConfigSetXkbModel(argv[i]);
- else if (!strcasecmp(argv[i-1], "xkblayout"))
- dmxConfigSetXkbLayout(argv[i]);
- else if (!strcasecmp(argv[i-1], "xkbvariant"))
- dmxConfigSetXkbVariant(argv[i]);
- else if (!strcasecmp(argv[i-1], "xkboptions"))
- dmxConfigSetXkbOptions(argv[i]);
- else
- dmxLog(dmxWarning,
- "-param requires: XkbRules, XkbModel, XkbLayout,"
- " XkbVariant, or XkbOptions\n");
- }
- retval = 3;
- }
- if (!serverGeneration) dmxConfigSetMaxScreens();
- return retval;
-}
-
-/** Provide succinct usage information for the DMX server. */
-void ddxUseMsg(void)
-{
- ErrorF("\n\nDevice Dependent Usage:\n");
- ErrorF("-display string Specify the back-end display(s)\n");
- ErrorF("-input string Specify input source for core device\n");
- ErrorF("-xinput string Specify input source for XInput device\n");
- ErrorF("-shadowfb Enable shadow frame buffer\n");
- ErrorF("-configfile file Read from a configuration file\n");
- ErrorF("-config config Select a specific configuration\n");
- ErrorF("-nomulticursor Turn of multiple cursor support\n");
- ErrorF("-fontpath Sets the default font path\n");
- ErrorF("-stat inter scrns Print out performance statistics\n");
- ErrorF("-syncbatch inter Set interval for XSync batching\n");
- ErrorF("-nooffscreenopt Disable offscreen optimization\n");
- ErrorF("-nosubdivprims Disable primitive subdivision\n");
- ErrorF(" optimization\n");
- ErrorF("-nowindowopt Disable lazy window creation optimization\n");
- ErrorF("-noxkb Disable use of the XKB extension with\n");
- ErrorF(" backend displays (cf. -kb).\n");
- ErrorF("-depth Specify the default root window depth\n");
- ErrorF("-norender Disable RENDER extension support\n");
-#ifdef GLXEXT
- ErrorF("-noglxproxy Disable GLX Proxy\n");
- ErrorF("-noglxswapgroup Disable swap group and swap barrier\n");
- ErrorF(" extensions in GLX proxy\n");
- ErrorF("-glxsyncswap Force XSync after swap buffers\n");
- ErrorF("-glxfinishswap Force glFinish after swap buffers\n");
-#endif
- ErrorF("-ignorebadfontpaths Ignore bad font paths during initialization\n");
- ErrorF("-addremovescreens Enable dynamic screen addition/removal\n");
- ErrorF("-param ... Specify configuration parameters (e.g.,\n");
- ErrorF(" XkbRules, XkbModel, XkbLayout, etc.)\n");
- ErrorF("\n");
- ErrorF(" If the -input string matches a -display string, then input\n"
- " is taken from that backend display. (XInput cannot be taken\n"
- " from a backend display.) Placing \",console\" after the\n"
- " display name will force a console window to be opened on\n"
- " that display in addition to the backend input. This is\n"
- " useful if the backend window does not cover the whole\n"
- " physical display.\n\n");
-
- ErrorF(" Otherwise, if the -input or -xinput string specifies another\n"
- " X display, then a console window will be created on that\n"
- " display. Placing \",windows\" or \",nowindows\" after the\n"
- " display name will control the display of window outlines in\n"
- " the console.\n\n");
-
- ErrorF(" -input or -xinput dummy specifies no input.\n");
- ErrorF(" -input or -xinput local specifies the use of a raw keyboard,\n"
- " mouse, or other (extension) device:\n"
- " -input local,kbd,ps2 will use a ps2 mouse\n"
- " -input local,kbd,ms will use a serial mouse\n"
- " -input local,usb-kbd,usb-mou will use USB devices \n"
- " -xinput local,usb-oth will use a non-mouse and\n"
- " non-keyboard USB device with XInput\n\n");
-
- ErrorF(" Special Keys:\n");
- ErrorF(" Ctrl-Alt-g Server grab/ungrab (console only)\n");
- ErrorF(" Ctrl-Alt-f Fine (1-pixel) mouse mode (console only)\n");
- ErrorF(" Ctrl-Alt-q Quit (core devices only)\n");
- ErrorF(" Ctrl-Alt-F* Switch to VC (local only)\n");
-}
+/*
+ * Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
+ *
+ * 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 on 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
+ * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
+ * 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:
+ * Kevin E. Martin <kem@redhat.com>
+ * David H. Dawes <dawes@xfree86.org>
+ * Rickard E. (Rik) Faith <faith@redhat.com>
+ *
+ */
+
+/** \file
+ * Provide expected functions for initialization from the ddx layer and
+ * global variables for the DMX server. */
+
+#ifdef HAVE_DMX_CONFIG_H
+#include <dmx-config.h>
+#endif
+
+#include "dmx.h"
+#include "dmxinit.h"
+#include "dmxsync.h"
+#include "dmxlog.h"
+#include "dmxinput.h"
+#include "dmxscrinit.h"
+#include "dmxcursor.h"
+#include "dmxfont.h"
+#include "config/dmxconfig.h"
+#include "dmxcb.h"
+#include "dmxprop.h"
+#include "dmxstat.h"
+#include "dmxpict.h"
+
+#include <X11/Xos.h> /* For gettimeofday */
+#include "dixstruct.h"
+#ifdef PANORAMIX
+#include "panoramiXsrv.h"
+#endif
+
+#include <signal.h> /* For SIGQUIT */
+
+#ifdef GLXEXT
+#include <GL/glx.h>
+#include <GL/glxint.h>
+#include "dmx_glxvisuals.h"
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#endif /* GLXEXT */
+
+/* Global variables available to all Xserver/hw/dmx routines. */
+int dmxNumScreens;
+DMXScreenInfo *dmxScreens;
+
+int dmxNumInputs;
+DMXInputInfo *dmxInputs;
+
+int dmxShadowFB = FALSE;
+
+XErrorEvent dmxLastErrorEvent;
+Bool dmxErrorOccurred = FALSE;
+
+char *dmxFontPath = NULL;
+
+Bool dmxOffScreenOpt = TRUE;
+
+Bool dmxSubdividePrimitives = TRUE;
+
+Bool dmxLazyWindowCreation = TRUE;
+
+Bool dmxUseXKB = TRUE;
+
+int dmxDepth = 0;
+
+#ifndef GLXEXT
+static Bool dmxGLXProxy = FALSE;
+#else
+Bool dmxGLXProxy = TRUE;
+
+Bool dmxGLXSwapGroupSupport = TRUE;
+
+Bool dmxGLXSyncSwap = FALSE;
+
+Bool dmxGLXFinishSwap = FALSE;
+#endif
+
+Bool dmxIgnoreBadFontPaths = FALSE;
+
+Bool dmxAddRemoveScreens = FALSE;
+
+/* dmxErrorHandler catches errors that occur when calling one of the
+ * back-end servers. Some of this code is based on _XPrintDefaultError
+ * in xc/lib/X11/XlibInt.c */
+static int dmxErrorHandler(Display *dpy, XErrorEvent *ev)
+{
+#define DMX_ERROR_BUF_SIZE 256
+ /* RATS: these buffers are only used in
+ * length-limited calls. */
+ char buf[DMX_ERROR_BUF_SIZE];
+ char request[DMX_ERROR_BUF_SIZE];
+ _XExtension *ext = NULL;
+
+ dmxErrorOccurred = TRUE;
+ dmxLastErrorEvent = *ev;
+
+ XGetErrorText(dpy, ev->error_code, buf, sizeof(buf));
+ dmxLog(dmxWarning, "dmxErrorHandler: %s\n", buf);
+
+ /* Find major opcode name */
+ if (ev->request_code < 128) {
+ XmuSnprintf(request, sizeof(request), "%d", ev->request_code);
+ XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf));
+ } else {
+ for (ext = dpy->ext_procs;
+ ext && ext->codes.major_opcode != ev->request_code;
+ ext = ext->next);
+ if (ext) strncpy(buf, ext->name, sizeof(buf));
+ else buf[0] = '\0';
+ }
+ dmxLog(dmxWarning, " Major opcode: %d (%s)\n",
+ ev->request_code, buf);
+
+ /* Find minor opcode name */
+ if (ev->request_code >= 128 && ext) {
+ XmuSnprintf(request, sizeof(request), "%d", ev->request_code);
+ XmuSnprintf(request, sizeof(request), "%s.%d",
+ ext->name, ev->minor_code);
+ XGetErrorDatabaseText(dpy, "XRequest", request, "", buf, sizeof(buf));
+ dmxLog(dmxWarning, " Minor opcode: %d (%s)\n",
+ ev->minor_code, buf);
+ }
+
+ /* Provide value information */
+ switch (ev->error_code) {
+ case BadValue:
+ dmxLog(dmxWarning, " Value: 0x%x\n",
+ ev->resourceid);
+ break;
+ case BadAtom:
+ dmxLog(dmxWarning, " AtomID: 0x%x\n",
+ ev->resourceid);
+ break;
+ default:
+ dmxLog(dmxWarning, " ResourceID: 0x%x\n",
+ ev->resourceid);
+ break;
+ }
+
+ /* Provide serial number information */
+ dmxLog(dmxWarning, " Failed serial number: %d\n",
+ ev->serial);
+ dmxLog(dmxWarning, " Current serial number: %d\n",
+ dpy->request);
+ return 0;
+}
+
+#ifdef GLXEXT
+static int dmxNOPErrorHandler(Display *dpy, XErrorEvent *ev)
+{
+ return 0;
+}
+#endif
+
+Bool dmxOpenDisplay(DMXScreenInfo *dmxScreen)
+{
+ if (!(dmxScreen->beDisplay = XOpenDisplay(dmxScreen->name)))
+ return FALSE;
+
+ dmxPropertyDisplay(dmxScreen);
+ return TRUE;
+}
+
+void dmxSetErrorHandler(DMXScreenInfo *dmxScreen)
+{
+ XSetErrorHandler(dmxErrorHandler);
+}
+
+static void dmxPrintScreenInfo(DMXScreenInfo *dmxScreen)
+{
+ XWindowAttributes attribs;
+ int ndepths = 0, *depths = NULL;
+ int i;
+ Display *dpy = dmxScreen->beDisplay;
+ Screen *s = DefaultScreenOfDisplay(dpy);
+ int scr = DefaultScreen(dpy);
+
+ XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &attribs);
+ if (!(depths = XListDepths(dpy, scr, &ndepths))) ndepths = 0;
+
+ dmxLogOutput(dmxScreen, "Name of display: %s\n", DisplayString(dpy));
+ dmxLogOutput(dmxScreen, "Version number: %d.%d\n",
+ ProtocolVersion(dpy), ProtocolRevision(dpy));
+ dmxLogOutput(dmxScreen, "Vendor string: %s\n", ServerVendor(dpy));
+ if (!strstr(ServerVendor(dpy), "XFree86")) {
+ dmxLogOutput(dmxScreen, "Vendor release: %d\n", VendorRelease(dpy));
+ } else {
+ /* This code based on xdpyinfo.c */
+ int v = VendorRelease(dpy);
+ int major = -1, minor = -1, patch = -1, subpatch = -1;
+
+ if (v < 336)
+ major = v / 100, minor = (v / 10) % 10, patch = v % 10;
+ else if (v < 3900) {
+ major = v / 1000;
+ minor = (v / 100) % 10;
+ if (((v / 10) % 10) || (v % 10)) {
+ patch = (v / 10) % 10;
+ if (v % 10) subpatch = v % 10;
+ }
+ } else if (v < 40000000) {
+ major = v / 1000;
+ minor = (v / 10) % 10;
+ if (v % 10) patch = v % 10;
+ } else {
+ major = v / 10000000;
+ minor = (v / 100000) % 100;
+ patch = (v / 1000) % 100;
+ if (v % 1000) subpatch = v % 1000;
+ }
+ dmxLogOutput(dmxScreen, "Vendor release: %d (XFree86 version: %d.%d",
+ v, major, minor);
+ if (patch > 0) dmxLogOutputCont(dmxScreen, ".%d", patch);
+ if (subpatch > 0) dmxLogOutputCont(dmxScreen, ".%d", subpatch);
+ dmxLogOutputCont(dmxScreen, ")\n");
+ }
+
+
+ dmxLogOutput(dmxScreen, "Dimensions: %dx%d pixels\n",
+ attribs.width, attribs.height);
+ dmxLogOutput(dmxScreen, "%d depths on screen %d: ", ndepths, scr);
+ for (i = 0; i < ndepths; i++)
+ dmxLogOutputCont(dmxScreen, "%c%d", i ? ',' : ' ', depths[i]);
+ dmxLogOutputCont(dmxScreen, "\n");
+ dmxLogOutput(dmxScreen, "Depth of root window: %d plane%s (%d)\n",
+ attribs.depth, attribs.depth == 1 ? "" : "s",
+ DisplayPlanes(dpy, scr));
+ dmxLogOutput(dmxScreen, "Number of colormaps: %d min, %d max\n",
+ MinCmapsOfScreen(s), MaxCmapsOfScreen(s));
+ dmxLogOutput(dmxScreen, "Options: backing-store %s, save-unders %s\n",
+ (DoesBackingStore (s) == NotUseful) ? "no" :
+ ((DoesBackingStore (s) == Always) ? "yes" : "when mapped"),
+ DoesSaveUnders (s) ? "yes" : "no");
+ dmxLogOutput(dmxScreen, "Window Manager running: %s\n",
+ (dmxScreen->WMRunningOnBE) ? "yes" : "no");
+
+ if (dmxScreen->WMRunningOnBE) {
+ dmxLogOutputWarning(dmxScreen,
+ "Window manager running "
+ "-- colormaps not supported\n");
+ }
+ XFree(depths);
+}
+
+void dmxGetScreenAttribs(DMXScreenInfo *dmxScreen)
+{
+ XWindowAttributes attribs;
+ Display *dpy = dmxScreen->beDisplay;
+#ifdef GLXEXT
+ int dummy;
+#endif
+
+ XGetWindowAttributes(dpy, DefaultRootWindow(dpy), &attribs);
+
+ dmxScreen->beWidth = attribs.width;
+ dmxScreen->beHeight = attribs.height;
+
+ /* Fill in missing geometry information */
+ if (dmxScreen->scrnXSign < 0) {
+ if (dmxScreen->scrnWidth) {
+ dmxScreen->scrnX = (attribs.width - dmxScreen->scrnWidth
+ - dmxScreen->scrnX);
+ } else {
+ dmxScreen->scrnWidth = attribs.width - dmxScreen->scrnX;
+ dmxScreen->scrnX = 0;
+ }
+ }
+ if (dmxScreen->scrnYSign < 0) {
+ if (dmxScreen->scrnHeight) {
+ dmxScreen->scrnY = (attribs.height - dmxScreen->scrnHeight
+ - dmxScreen->scrnY);
+ } else {
+ dmxScreen->scrnHeight = attribs.height - dmxScreen->scrnY;
+ dmxScreen->scrnY = 0;
+ }
+ }
+ if (!dmxScreen->scrnWidth)
+ dmxScreen->scrnWidth = attribs.width - dmxScreen->scrnX;
+ if (!dmxScreen->scrnHeight)
+ dmxScreen->scrnHeight = attribs.height - dmxScreen->scrnY;
+
+ if (!dmxScreen->rootWidth) dmxScreen->rootWidth = dmxScreen->scrnWidth;
+ if (!dmxScreen->rootHeight) dmxScreen->rootHeight = dmxScreen->scrnHeight;
+ if (dmxScreen->rootWidth + dmxScreen->rootX > dmxScreen->scrnWidth)
+ dmxScreen->rootWidth = dmxScreen->scrnWidth - dmxScreen->rootX;
+ if (dmxScreen->rootHeight + dmxScreen->rootY > dmxScreen->scrnHeight)
+ dmxScreen->rootHeight = dmxScreen->scrnHeight - dmxScreen->rootY;
+
+ /* FIXME: Get these from the back-end server */
+ dmxScreen->beXDPI = 75;
+ dmxScreen->beYDPI = 75;
+
+ dmxScreen->beDepth = attribs.depth; /* FIXME: verify that this
+ * works always. In
+ * particular, this will work
+ * well for depth=16, will fail
+ * because of colormap issues
+ * at depth 8. More work needs
+ * to be done here. */
+
+ if (dmxScreen->beDepth <= 8) dmxScreen->beBPP = 8;
+ else if (dmxScreen->beDepth <= 16) dmxScreen->beBPP = 16;
+ else dmxScreen->beBPP = 32;
+
+#ifdef GLXEXT
+ /* get the majorOpcode for the back-end GLX extension */
+ XQueryExtension(dpy, "GLX", &dmxScreen->glxMajorOpcode,
+ &dummy, &dmxScreen->glxErrorBase);
+#endif
+
+ dmxPrintScreenInfo(dmxScreen);
+ dmxLogOutput(dmxScreen, "%dx%d+%d+%d on %dx%d at depth=%d, bpp=%d\n",
+ dmxScreen->scrnWidth, dmxScreen->scrnHeight,
+ dmxScreen->scrnX, dmxScreen->scrnY,
+ dmxScreen->beWidth, dmxScreen->beHeight,
+ dmxScreen->beDepth, dmxScreen->beBPP);
+ if (dmxScreen->beDepth == 8)
+ dmxLogOutputWarning(dmxScreen,
+ "Support for depth == 8 is not complete\n");
+}
+
+Bool dmxGetVisualInfo(DMXScreenInfo *dmxScreen)
+{
+ int i;
+ XVisualInfo visinfo;
+
+ visinfo.screen = DefaultScreen(dmxScreen->beDisplay);
+ dmxScreen->beVisuals = XGetVisualInfo(dmxScreen->beDisplay,
+ VisualScreenMask,
+ &visinfo,
+ &dmxScreen->beNumVisuals);
+
+ dmxScreen->beDefVisualIndex = -1;
+
+ if (defaultColorVisualClass >= 0 || dmxDepth > 0) {
+ for (i = 0; i < dmxScreen->beNumVisuals; i++)
+ if (defaultColorVisualClass >= 0) {
+ if (dmxScreen->beVisuals[i].class == defaultColorVisualClass) {
+ if (dmxDepth > 0) {
+ if (dmxScreen->beVisuals[i].depth == dmxDepth) {
+ dmxScreen->beDefVisualIndex = i;
+ break;
+ }
+ } else {
+ dmxScreen->beDefVisualIndex = i;
+ break;
+ }
+ }
+ } else if (dmxScreen->beVisuals[i].depth == dmxDepth) {
+ dmxScreen->beDefVisualIndex = i;
+ break;
+ }
+ } else {
+ visinfo.visualid =
+ XVisualIDFromVisual(DefaultVisual(dmxScreen->beDisplay,
+ visinfo.screen));
+
+ for (i = 0; i < dmxScreen->beNumVisuals; i++)
+ if (visinfo.visualid == dmxScreen->beVisuals[i].visualid) {
+ dmxScreen->beDefVisualIndex = i;
+ break;
+ }
+ }
+
+ for (i = 0; i < dmxScreen->beNumVisuals; i++)
+ dmxLogVisual(dmxScreen, &dmxScreen->beVisuals[i],
+ (i == dmxScreen->beDefVisualIndex));
+
+ return dmxScreen->beDefVisualIndex >= 0;
+}
+
+void dmxGetColormaps(DMXScreenInfo *dmxScreen)
+{
+ int i;
+
+ dmxScreen->beNumDefColormaps = dmxScreen->beNumVisuals;
+ dmxScreen->beDefColormaps = malloc(dmxScreen->beNumDefColormaps *
+ sizeof(*dmxScreen->beDefColormaps));
+
+ for (i = 0; i < dmxScreen->beNumDefColormaps; i++)
+ dmxScreen->beDefColormaps[i] =
+ XCreateColormap(dmxScreen->beDisplay,
+ DefaultRootWindow(dmxScreen->beDisplay),
+ dmxScreen->beVisuals[i].visual,
+ AllocNone);
+
+ dmxScreen->beBlackPixel = BlackPixel(dmxScreen->beDisplay,
+ DefaultScreen(dmxScreen->beDisplay));
+ dmxScreen->beWhitePixel = WhitePixel(dmxScreen->beDisplay,
+ DefaultScreen(dmxScreen->beDisplay));
+}
+
+void dmxGetPixmapFormats(DMXScreenInfo *dmxScreen)
+{
+ dmxScreen->beDepths =
+ XListDepths(dmxScreen->beDisplay, DefaultScreen(dmxScreen->beDisplay),
+ &dmxScreen->beNumDepths);
+
+ dmxScreen->bePixmapFormats =
+ XListPixmapFormats(dmxScreen->beDisplay,
+ &dmxScreen->beNumPixmapFormats);
+}
+
+static Bool dmxSetPixmapFormats(ScreenInfo *pScreenInfo,
+ DMXScreenInfo *dmxScreen)
+{
+ XPixmapFormatValues *bePixmapFormat;
+ PixmapFormatRec *format;
+ int i, j;
+
+ pScreenInfo->imageByteOrder = ImageByteOrder(dmxScreen->beDisplay);
+ pScreenInfo->bitmapScanlineUnit = BitmapUnit(dmxScreen->beDisplay);
+ pScreenInfo->bitmapScanlinePad = BitmapPad(dmxScreen->beDisplay);
+ pScreenInfo->bitmapBitOrder = BitmapBitOrder(dmxScreen->beDisplay);
+
+ pScreenInfo->numPixmapFormats = 0;
+ for (i = 0; i < dmxScreen->beNumPixmapFormats; i++) {
+ bePixmapFormat = &dmxScreen->bePixmapFormats[i];
+ for (j = 0; j < dmxScreen->beNumDepths; j++)
+ if ((bePixmapFormat->depth == 1) ||
+ (bePixmapFormat->depth == dmxScreen->beDepths[j])) {
+ format = &pScreenInfo->formats[pScreenInfo->numPixmapFormats];
+
+ format->depth = bePixmapFormat->depth;
+ format->bitsPerPixel = bePixmapFormat->bits_per_pixel;
+ format->scanlinePad = bePixmapFormat->scanline_pad;
+
+ pScreenInfo->numPixmapFormats++;
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+void dmxCheckForWM(DMXScreenInfo *dmxScreen)
+{
+ Status status;
+ XWindowAttributes xwa;
+
+ status = XGetWindowAttributes(dmxScreen->beDisplay,
+ DefaultRootWindow(dmxScreen->beDisplay),
+ &xwa);
+ dmxScreen->WMRunningOnBE =
+ (status &&
+ ((xwa.all_event_masks & SubstructureRedirectMask) ||
+ (xwa.all_event_masks & SubstructureNotifyMask)));
+}
+
+/** Initialize the display and collect relevant information about the
+ * display properties */
+static void dmxDisplayInit(DMXScreenInfo *dmxScreen)
+{
+ if (!dmxOpenDisplay(dmxScreen))
+ dmxLog(dmxFatal,
+ "dmxOpenDisplay: Unable to open display %s\n",
+ dmxScreen->name);
+
+ dmxSetErrorHandler(dmxScreen);
+ dmxCheckForWM(dmxScreen);
+ dmxGetScreenAttribs(dmxScreen);
+
+ if (!dmxGetVisualInfo(dmxScreen))
+ dmxLog(dmxFatal, "dmxGetVisualInfo: No matching visuals found\n");
+
+ dmxGetColormaps(dmxScreen);
+ dmxGetPixmapFormats(dmxScreen);
+}
+
+/* If this doesn't compile, just add || defined(yoursystem) to the line
+ * below. This information is to help with bug reports and is not
+ * critical. */
+#if !defined(_POSIX_SOURCE)
+static const char *dmxExecOS(void) { return ""; }
+#else
+#include <sys/utsname.h>
+static const char *dmxExecOS(void)
+{
+ static char buffer[128];
+ static int initialized = 0;
+ struct utsname u;
+
+ if (!initialized++) {
+ memset(buffer, 0, sizeof(buffer));
+ uname(&u);
+ XmuSnprintf(buffer, sizeof(buffer)-1, "%s %s %s",
+ u.sysname, u.release, u.version);
+ }
+ return buffer;
+}
+#endif
+
+static const char *dmxBuildCompiler(void)
+{
+ static char buffer[128];
+ static int initialized = 0;
+
+ if (!initialized++) {
+ memset(buffer, 0, sizeof(buffer));
+#if defined(__GNUC__) && defined(__GNUC_MINOR__) &&defined(__GNUC_PATCHLEVEL__)
+ XmuSnprintf(buffer, sizeof(buffer)-1, "gcc %d.%d.%d",
+ __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
+#endif
+ }
+ return buffer;
+}
+
+static const char *dmxExecHost(void)
+{
+ static char buffer[128];
+ static int initialized = 0;
+
+ if (!initialized++) {
+ memset(buffer, 0, sizeof(buffer));
+ XmuGetHostname(buffer, sizeof(buffer) - 1);
+ }
+ return buffer;
+}
+
+/** This routine is called in Xserver/dix/main.c from \a main(). */
+void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[])
+{
+ int i;
+ static unsigned long dmxGeneration = 0;
+#ifdef GLXEXT
+ Bool glxSupported = TRUE;
+#endif
+
+ if (dmxGeneration != serverGeneration) {
+ int vendrel = VENDOR_RELEASE;
+ int major, minor, year, month, day;
+
+ dmxGeneration = serverGeneration;
+
+ major = vendrel / 100000000;
+ vendrel -= major * 100000000;
+ minor = vendrel / 1000000;
+ vendrel -= minor * 1000000;
+ year = vendrel / 10000;
+ vendrel -= year * 10000;
+ month = vendrel / 100;
+ vendrel -= month * 100;
+ day = vendrel;
+
+ /* Add other epoch tests here */
+ if (major > 0 && minor > 0) year += 2000;
+
+ dmxLog(dmxInfo, "Generation: %d\n", dmxGeneration);
+ dmxLog(dmxInfo, "DMX version: %d.%d.%02d%02d%02d (%s)\n",
+ major, minor, year, month, day, VENDOR_STRING);
+
+ SetVendorRelease(VENDOR_RELEASE);
+ SetVendorString(VENDOR_STRING);
+
+ if (dmxGeneration == 1) {
+ dmxLog(dmxInfo, "DMX Build OS: %s (%s)\n", OSNAME, OSVENDOR);
+ dmxLog(dmxInfo, "DMX Build Compiler: %s\n", dmxBuildCompiler());
+ dmxLog(dmxInfo, "DMX Execution OS: %s\n", dmxExecOS());
+ dmxLog(dmxInfo, "DMX Execution Host: %s\n", dmxExecHost());
+ }
+ dmxLog(dmxInfo, "MAXSCREENS: %d\n", MAXSCREENS);
+
+ for (i = 0; i < dmxNumScreens; i++) {
+ if (dmxScreens[i].beDisplay)
+ dmxLog(dmxWarning, "Display \"%s\" still open\n",
+ dmxScreens[i].name);
+ dmxStatFree(dmxScreens[i].stat);
+ dmxScreens[i].stat = NULL;
+ }
+ for (i = 0; i < dmxNumInputs; i++) dmxInputFree(&dmxInputs[i]);
+ free(dmxScreens);
+ free(dmxInputs);
+ dmxScreens = NULL;
+ dmxInputs = NULL;
+ dmxNumScreens = 0;
+ dmxNumInputs = 0;
+ }
+
+ /* Make sure that the command-line arguments are sane. */
+ if (dmxAddRemoveScreens && dmxGLXProxy) {
+ /* Currently it is not possible to support GLX and Render
+ * extensions with dynamic screen addition/removal due to the
+ * state that each extension keeps, which cannot be restored. */
+ dmxLog(dmxWarning,
+ "GLX Proxy and Render extensions do not yet support dynamic\n");
+ dmxLog(dmxWarning,
+ "screen addition and removal. Please specify -noglxproxy\n");
+ dmxLog(dmxWarning,
+ "and -norender on the command line or in the configuration\n");
+ dmxLog(dmxWarning,
+ "file to disable these two extensions if you wish to use\n");
+ dmxLog(dmxWarning,
+ "the dynamic addition and removal of screens support.\n");
+ dmxLog(dmxFatal,
+ "Dynamic screen addition/removal error (see above).\n");
+ }
+
+ /* ddxProcessArgument has been called at this point, but any data
+ * from the configuration file has not been applied. Do so, and be
+ * sure we have at least one back-end display. */
+ dmxConfigConfigure();
+ if (!dmxNumScreens)
+ dmxLog(dmxFatal, "InitOutput: no back-end displays found\n");
+ if (!dmxNumInputs)
+ dmxLog(dmxInfo, "InitOutput: no inputs found\n");
+
+ /* Disable lazy window creation optimization if offscreen
+ * optimization is disabled */
+ if (!dmxOffScreenOpt && dmxLazyWindowCreation) {
+ dmxLog(dmxInfo,
+ "InitOutput: Disabling lazy window creation optimization\n");
+ dmxLog(dmxInfo,
+ " since it requires the offscreen optimization\n");
+ dmxLog(dmxInfo,
+ " to function properly.\n");
+ dmxLazyWindowCreation = FALSE;
+ }
+
+ /* Open each display and gather information about it. */
+ for (i = 0; i < dmxNumScreens; i++)
+ dmxDisplayInit(&dmxScreens[i]);
+
+#if PANORAMIX
+ /* Register a Xinerama callback which will run from within
+ * PanoramiXCreateConnectionBlock. We can use the callback to
+ * determine if Xinerama is loaded and to check the visuals
+ * determined by PanoramiXConsolidate. */
+ XineramaRegisterConnectionBlockCallback(dmxConnectionBlockCallback);
+#endif
+
+ /* Since we only have a single screen thus far, we only need to set
+ the pixmap formats to match that screen. FIXME: this isn't true.*/
+ if (!dmxSetPixmapFormats(pScreenInfo, &dmxScreens[0])) return;
+
+ /* Might want to install a signal handler to allow cleaning up after
+ * unexpected signals. The DIX/OS layer already handles SIGINT and
+ * SIGTERM, so everything is OK for expected signals. --DD
+ *
+ * SIGHUP, SIGINT, and SIGTERM are trapped in os/connection.c
+ * SIGQUIT is another common signal that is sent from the keyboard.
+ * Trap it here, to ensure that the keyboard modifier map and other
+ * state for the input devices are restored. (This makes the
+ * behavior of SIGQUIT somewhat unexpected, since it will be the
+ * same as the behavior of SIGINT. However, leaving the modifier
+ * map of the input devices empty is even more unexpected.) --RF
+ */
+ OsSignal(SIGQUIT, GiveUp);
+
+#ifdef GLXEXT
+ /* Check if GLX extension exists on all back-end servers */
+ for (i = 0; i < dmxNumScreens; i++)
+ glxSupported &= (dmxScreens[i].glxMajorOpcode > 0);
+#endif
+
+ /* Tell dix layer about the backend displays */
+ for (i = 0; i < dmxNumScreens; i++) {
+
+#ifdef GLXEXT
+ if (glxSupported) {
+ /*
+ * Builds GLX configurations from the list of visuals
+ * supported by the back-end server, and give that
+ * configuration list to the glx layer - so that he will
+ * build the visuals accordingly.
+ */
+
+ DMXScreenInfo *dmxScreen = &dmxScreens[i];
+ __GLXvisualConfig *configs = NULL;
+ dmxGlxVisualPrivate **configprivs = NULL;
+ int nconfigs = 0;
+ int (*oldErrorHandler)(Display *, XErrorEvent *);
+ int i;
+
+ /* Catch errors if when using an older GLX w/o FBconfigs */
+ oldErrorHandler = XSetErrorHandler(dmxNOPErrorHandler);
+
+ /* Get FBConfigs of the back-end server */
+ dmxScreen->fbconfigs = GetGLXFBConfigs(dmxScreen->beDisplay,
+ dmxScreen->glxMajorOpcode,
+ &dmxScreen->numFBConfigs);
+
+ XSetErrorHandler(oldErrorHandler);
+
+ dmxScreen->glxVisuals =
+ GetGLXVisualConfigs(dmxScreen->beDisplay,
+ DefaultScreen(dmxScreen->beDisplay),
+ &dmxScreen->numGlxVisuals);
+
+ if (dmxScreen->fbconfigs) {
+ configs =
+ GetGLXVisualConfigsFromFBConfigs(dmxScreen->fbconfigs,
+ dmxScreen->numFBConfigs,
+ dmxScreen->beVisuals,
+ dmxScreen->beNumVisuals,
+ dmxScreen->glxVisuals,
+ dmxScreen->numGlxVisuals,
+ &nconfigs);
+ } else {
+ configs = dmxScreen->glxVisuals;
+ nconfigs = dmxScreen->numGlxVisuals;
+ }
+
+ configprivs = malloc(nconfigs * sizeof(dmxGlxVisualPrivate*));
+
+ if (configs != NULL && configprivs != NULL) {
+
+ /* Initialize our private info for each visual
+ * (currently only x_visual_depth and x_visual_class)
+ */
+ for (i = 0; i < nconfigs; i++) {
+
+ configprivs[i] = (dmxGlxVisualPrivate *)
+ malloc(sizeof(dmxGlxVisualPrivate));
+ configprivs[i]->x_visual_depth = 0;
+ configprivs[i]->x_visual_class = 0;
+
+ /* Find the visual depth */
+ if (configs[i].vid > 0) {
+ int j;
+ for (j = 0; j < dmxScreen->beNumVisuals; j++) {
+ if (dmxScreen->beVisuals[j].visualid ==
+ configs[i].vid) {
+ configprivs[i]->x_visual_depth =
+ dmxScreen->beVisuals[j].depth;
+ configprivs[i]->x_visual_class =
+ dmxScreen->beVisuals[j].class;
+ break;
+ }
+ }
+ }
+ }
+
+ XFlush(dmxScreen->beDisplay);
+ }
+ }
+#endif /* GLXEXT */
+
+ AddScreen(dmxScreenInit, argc, argv);
+ }
+
+ /* Compute origin information. */
+ dmxInitOrigins();
+
+ /* Compute overlap information. */
+ dmxInitOverlap();
+
+ /* Make sure there is a global width/height available */
+ dmxComputeWidthHeight(DMX_NO_RECOMPUTE_BOUNDING_BOX);
+
+ /* FIXME: The following is temporarily placed here. When the DMX
+ * extension is available, it will be move there.
+ */
+ dmxInitFonts();
+
+ /* Initialize the render extension */
+ if (!noRenderExtension)
+ dmxInitRender();
+
+ /* Initialized things that need timer hooks */
+ dmxStatInit();
+ dmxSyncInit(); /* Calls RegisterBlockAndWakeupHandlers */
+
+ dmxLog(dmxInfo, "Shadow framebuffer support %s\n",
+ dmxShadowFB ? "enabled" : "disabled");
+}
+
+/* RATS: Assuming the fp string (which comes from the command-line argv
+ vector) is NULL-terminated, the buffer is large enough for the
+ strcpy. */
+static void dmxSetDefaultFontPath(char *fp)
+{
+ int fplen = strlen(fp) + 1;
+
+ if (dmxFontPath) {
+ int len;
+
+ len = strlen(dmxFontPath);
+ dmxFontPath = realloc(dmxFontPath, len+fplen+1);
+ dmxFontPath[len] = ',';
+ strncpy(&dmxFontPath[len+1], fp, fplen);
+ } else {
+ dmxFontPath = malloc(fplen);
+ strncpy(dmxFontPath, fp, fplen);
+ }
+
+ defaultFontPath = dmxFontPath;
+}
+
+/** This function is called in Xserver/os/utils.c from \a AbortServer().
+ * We must ensure that backend and console state is restored in the
+ * event the server shutdown wasn't clean. */
+void AbortDDX(enum ExitCode error)
+{
+ int i;
+
+ for (i=0; i < dmxNumScreens; i++) {
+ DMXScreenInfo *dmxScreen = &dmxScreens[i];
+
+ if (dmxScreen->beDisplay) XCloseDisplay(dmxScreen->beDisplay);
+ dmxScreen->beDisplay = NULL;
+ }
+}
+
+#ifdef DDXBEFORERESET
+/* This function is called in Xserver/dix/dispatch.c */
+void ddxBeforeReset(void)
+{
+}
+#endif
+
+/** This function is called in Xserver/dix/main.c from \a main() when
+ * dispatchException & DE_TERMINATE (which is the only way to exit the
+ * main loop without an interruption. */
+void ddxGiveUp(enum ExitCode error)
+{
+ AbortDDX(error);
+}
+
+/** This function is called in Xserver/os/osinit.c from \a OsInit(). */
+void OsVendorInit(void)
+{
+}
+
+/** This function is called in Xserver/os/utils.c from \a FatalError()
+ * and \a VFatalError(). (Note that setting the function pointer \a
+ * OsVendorVErrorFProc will cause \a VErrorF() (which is called by the
+ * two routines mentioned here, as well as by others) to use the
+ * referenced routine instead of \a vfprintf().) */
+void OsVendorFatalError(void)
+{
+}
+
+/** Process our command line arguments. */
+int ddxProcessArgument(int argc, char *argv[], int i)
+{
+ int retval = 0;
+
+ if (!strcmp(argv[i], "-display")) {
+ if (++i < argc) dmxConfigStoreDisplay(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-inputfrom") || !strcmp(argv[i], "-input")) {
+ if (++i < argc) dmxConfigStoreInput(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-xinputfrom") || !strcmp(argv[i],"-xinput")) {
+ if (++i < argc) dmxConfigStoreXInput(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-noshadowfb")) {
+ dmxLog(dmxWarning,
+ "-noshadowfb has been deprecated "
+ "since it is now the default\n");
+ dmxShadowFB = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-nomulticursor")) {
+ dmxCursorNoMulti();
+ retval = 1;
+ } else if (!strcmp(argv[i], "-shadowfb")) {
+ dmxShadowFB = TRUE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-configfile")) {
+ if (++i < argc) dmxConfigStoreFile(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-config")) {
+ if (++i < argc) dmxConfigStoreConfig(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-fontpath")) {
+ if (++i < argc) dmxSetDefaultFontPath(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-stat")) {
+ if ((i += 2) < argc) dmxStatActivate(argv[i-1], argv[i]);
+ retval = 3;
+ } else if (!strcmp(argv[i], "-syncbatch")) {
+ if (++i < argc) dmxSyncActivate(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-nooffscreenopt")) {
+ dmxOffScreenOpt = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-nosubdivprims")) {
+ dmxSubdividePrimitives = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-nowindowopt")) {
+ dmxLazyWindowCreation = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-noxkb")) {
+ dmxUseXKB = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-depth")) {
+ if (++i < argc) dmxDepth = atoi(argv[i]);
+ retval = 2;
+ } else if (!strcmp(argv[i], "-norender")) {
+ noRenderExtension = TRUE;
+ retval = 1;
+#ifdef GLXEXT
+ } else if (!strcmp(argv[i], "-noglxproxy")) {
+ dmxGLXProxy = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-noglxswapgroup")) {
+ dmxGLXSwapGroupSupport = FALSE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-glxsyncswap")) {
+ dmxGLXSyncSwap = TRUE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-glxfinishswap")) {
+ dmxGLXFinishSwap = TRUE;
+ retval = 1;
+#endif
+ } else if (!strcmp(argv[i], "-ignorebadfontpaths")) {
+ dmxIgnoreBadFontPaths = TRUE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-addremovescreens")) {
+ dmxAddRemoveScreens = TRUE;
+ retval = 1;
+ } else if (!strcmp(argv[i], "-param")) {
+ if ((i += 2) < argc) {
+ if (!strcasecmp(argv[i-1], "xkbrules"))
+ dmxConfigSetXkbRules(argv[i]);
+ else if (!strcasecmp(argv[i-1], "xkbmodel"))
+ dmxConfigSetXkbModel(argv[i]);
+ else if (!strcasecmp(argv[i-1], "xkblayout"))
+ dmxConfigSetXkbLayout(argv[i]);
+ else if (!strcasecmp(argv[i-1], "xkbvariant"))
+ dmxConfigSetXkbVariant(argv[i]);
+ else if (!strcasecmp(argv[i-1], "xkboptions"))
+ dmxConfigSetXkbOptions(argv[i]);
+ else
+ dmxLog(dmxWarning,
+ "-param requires: XkbRules, XkbModel, XkbLayout,"
+ " XkbVariant, or XkbOptions\n");
+ }
+ retval = 3;
+ }
+ if (!serverGeneration) dmxConfigSetMaxScreens();
+ return retval;
+}
+
+/** Provide succinct usage information for the DMX server. */
+void ddxUseMsg(void)
+{
+ ErrorF("\n\nDevice Dependent Usage:\n");
+ ErrorF("-display string Specify the back-end display(s)\n");
+ ErrorF("-input string Specify input source for core device\n");
+ ErrorF("-xinput string Specify input source for XInput device\n");
+ ErrorF("-shadowfb Enable shadow frame buffer\n");
+ ErrorF("-configfile file Read from a configuration file\n");
+ ErrorF("-config config Select a specific configuration\n");
+ ErrorF("-nomulticursor Turn of multiple cursor support\n");
+ ErrorF("-fontpath Sets the default font path\n");
+ ErrorF("-stat inter scrns Print out performance statistics\n");
+ ErrorF("-syncbatch inter Set interval for XSync batching\n");
+ ErrorF("-nooffscreenopt Disable offscreen optimization\n");
+ ErrorF("-nosubdivprims Disable primitive subdivision\n");
+ ErrorF(" optimization\n");
+ ErrorF("-nowindowopt Disable lazy window creation optimization\n");
+ ErrorF("-noxkb Disable use of the XKB extension with\n");
+ ErrorF(" backend displays (cf. -kb).\n");
+ ErrorF("-depth Specify the default root window depth\n");
+ ErrorF("-norender Disable RENDER extension support\n");
+#ifdef GLXEXT
+ ErrorF("-noglxproxy Disable GLX Proxy\n");
+ ErrorF("-noglxswapgroup Disable swap group and swap barrier\n");
+ ErrorF(" extensions in GLX proxy\n");
+ ErrorF("-glxsyncswap Force XSync after swap buffers\n");
+ ErrorF("-glxfinishswap Force glFinish after swap buffers\n");
+#endif
+ ErrorF("-ignorebadfontpaths Ignore bad font paths during initialization\n");
+ ErrorF("-addremovescreens Enable dynamic screen addition/removal\n");
+ ErrorF("-param ... Specify configuration parameters (e.g.,\n");
+ ErrorF(" XkbRules, XkbModel, XkbLayout, etc.)\n");
+ ErrorF("\n");
+ ErrorF(" If the -input string matches a -display string, then input\n"
+ " is taken from that backend display. (XInput cannot be taken\n"
+ " from a backend display.) Placing \",console\" after the\n"
+ " display name will force a console window to be opened on\n"
+ " that display in addition to the backend input. This is\n"
+ " useful if the backend window does not cover the whole\n"
+ " physical display.\n\n");
+
+ ErrorF(" Otherwise, if the -input or -xinput string specifies another\n"
+ " X display, then a console window will be created on that\n"
+ " display. Placing \",windows\" or \",nowindows\" after the\n"
+ " display name will control the display of window outlines in\n"
+ " the console.\n\n");
+
+ ErrorF(" -input or -xinput dummy specifies no input.\n");
+ ErrorF(" -input or -xinput local specifies the use of a raw keyboard,\n"
+ " mouse, or other (extension) device:\n"
+ " -input local,kbd,ps2 will use a ps2 mouse\n"
+ " -input local,kbd,ms will use a serial mouse\n"
+ " -input local,usb-kbd,usb-mou will use USB devices \n"
+ " -xinput local,usb-oth will use a non-mouse and\n"
+ " non-keyboard USB device with XInput\n\n");
+
+ ErrorF(" Special Keys:\n");
+ ErrorF(" Ctrl-Alt-g Server grab/ungrab (console only)\n");
+ ErrorF(" Ctrl-Alt-f Fine (1-pixel) mouse mode (console only)\n");
+ ErrorF(" Ctrl-Alt-q Quit (core devices only)\n");
+ ErrorF(" Ctrl-Alt-F* Switch to VC (local only)\n");
+}
diff --git a/xorg-server/hw/kdrive/src/kdrive.c b/xorg-server/hw/kdrive/src/kdrive.c
index 7d424dbcc..85fe190fc 100644
--- a/xorg-server/hw/kdrive/src/kdrive.c
+++ b/xorg-server/hw/kdrive/src/kdrive.c
@@ -233,7 +233,7 @@ KdProcessSwitch (void)
#ifndef _MSC_VER
void
-AbortDDX(void)
+AbortDDX(enum ExitCode error)
{
KdDisableScreens ();
if (kdOsFuncs)
@@ -250,9 +250,9 @@ AbortDDX(void)
}
void
-ddxGiveUp (void)
+ddxGiveUp (enum ExitCode error)
{
- AbortDDX ();
+ AbortDDX (error);
}
#endif
diff --git a/xorg-server/hw/vfb/InitOutput.c b/xorg-server/hw/vfb/InitOutput.c
index 04253dc5a..31ed50533 100644
--- a/xorg-server/hw/vfb/InitOutput.c
+++ b/xorg-server/hw/vfb/InitOutput.c
@@ -1,969 +1,969 @@
-/*
-
-Copyright 1993, 1998 The Open Group
-
-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.
-
-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 OPEN GROUP 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 Open Group 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 Open Group.
-
-*/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#if defined(WIN32)
-#include <X11/Xwinsock.h>
-#endif
-#include <stdio.h>
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include <X11/Xos.h>
-#include "scrnintstr.h"
-#include "servermd.h"
-#define PSZ 8
-#include "fb.h"
-#include "mibstore.h"
-#include "colormapst.h"
-#include "gcstruct.h"
-#include "input.h"
-#include "mipointer.h"
-#include "micmap.h"
-#include <sys/types.h>
-#ifdef HAS_MMAP
-#include <sys/mman.h>
-#ifndef MAP_FILE
-#define MAP_FILE 0
-#endif
-#endif /* HAS_MMAP */
-#include <sys/stat.h>
-#include <errno.h>
-#ifndef WIN32
-#include <sys/param.h>
-#endif
-#include <X11/XWDFile.h>
-#ifdef HAS_SHM
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#endif /* HAS_SHM */
-#include "dix.h"
-#include "miline.h"
-
-#define VFB_DEFAULT_WIDTH 1280
-#define VFB_DEFAULT_HEIGHT 1024
-#define VFB_DEFAULT_DEPTH 8
-#define VFB_DEFAULT_WHITEPIXEL 1
-#define VFB_DEFAULT_BLACKPIXEL 0
-#define VFB_DEFAULT_LINEBIAS 0
-#define XWD_WINDOW_NAME_LEN 60
-
-typedef struct
-{
- int width;
- int paddedBytesWidth;
- int paddedWidth;
- int height;
- int depth;
- int bitsPerPixel;
- int sizeInBytes;
- int ncolors;
- char *pfbMemory;
- XWDColor *pXWDCmap;
- XWDFileHeader *pXWDHeader;
- Pixel blackPixel;
- Pixel whitePixel;
- unsigned int lineBias;
- CloseScreenProcPtr closeScreen;
-
-#ifdef HAS_MMAP
- int mmap_fd;
- char mmap_file[MAXPATHLEN];
-#endif
-
-#ifdef HAS_SHM
- int shmid;
-#endif
-} vfbScreenInfo, *vfbScreenInfoPtr;
-
-static int vfbNumScreens;
-static vfbScreenInfo *vfbScreens;
-static vfbScreenInfo defaultScreenInfo = {
- .width = VFB_DEFAULT_WIDTH,
- .height = VFB_DEFAULT_HEIGHT,
- .depth = VFB_DEFAULT_DEPTH,
- .blackPixel = VFB_DEFAULT_BLACKPIXEL,
- .whitePixel = VFB_DEFAULT_WHITEPIXEL,
- .lineBias = VFB_DEFAULT_LINEBIAS,
-};
-static Bool vfbPixmapDepths[33];
-#ifdef HAS_MMAP
-static char *pfbdir = NULL;
-#endif
-typedef enum { NORMAL_MEMORY_FB, SHARED_MEMORY_FB, MMAPPED_FILE_FB } fbMemType;
-static fbMemType fbmemtype = NORMAL_MEMORY_FB;
-static char needswap = 0;
-static Bool Render = TRUE;
-
-#define swapcopy16(_dst, _src) \
- if (needswap) { CARD16 _s = _src; cpswaps(_s, _dst); } \
- else _dst = _src;
-
-#define swapcopy32(_dst, _src) \
- if (needswap) { CARD32 _s = _src; cpswapl(_s, _dst); } \
- else _dst = _src;
-
-
-static void
-vfbInitializePixmapDepths(void)
-{
- int i;
- vfbPixmapDepths[1] = TRUE; /* always need bitmaps */
- for (i = 2; i <= 32; i++)
- vfbPixmapDepths[i] = FALSE;
-}
-
-static int
-vfbBitsPerPixel(int depth)
-{
- if (depth == 1) return 1;
- else if (depth <= 8) return 8;
- else if (depth <= 16) return 16;
- else return 32;
-}
-
-void
-ddxGiveUp(void)
-{
- int i;
-
- /* clean up the framebuffers */
-
- switch (fbmemtype)
- {
-#ifdef HAS_MMAP
- case MMAPPED_FILE_FB:
- for (i = 0; i < vfbNumScreens; i++)
- {
- if (-1 == unlink(vfbScreens[i].mmap_file))
- {
- perror("unlink");
- ErrorF("unlink %s failed, %s",
- vfbScreens[i].mmap_file, strerror(errno));
- }
- }
- break;
-#else /* HAS_MMAP */
- case MMAPPED_FILE_FB:
- break;
-#endif /* HAS_MMAP */
-
-#ifdef HAS_SHM
- case SHARED_MEMORY_FB:
- for (i = 0; i < vfbNumScreens; i++)
- {
- if (-1 == shmdt((char *)vfbScreens[i].pXWDHeader))
- {
- perror("shmdt");
- ErrorF("shmdt failed, %s", strerror(errno));
- }
- }
- break;
-#else /* HAS_SHM */
- case SHARED_MEMORY_FB:
- break;
-#endif /* HAS_SHM */
-
- case NORMAL_MEMORY_FB:
- for (i = 0; i < vfbNumScreens; i++)
- {
- free(vfbScreens[i].pXWDHeader);
- }
- break;
- }
-}
-
-void
-AbortDDX(void)
-{
- ddxGiveUp();
-}
-
-#ifdef __APPLE__
-void
-DarwinHandleGUI(int argc, char *argv[])
-{
-}
-#endif
-
-void
-OsVendorInit(void)
-{
-}
-
-void
-OsVendorFatalError(void)
-{
-}
-
-#if defined(DDXBEFORERESET)
-void ddxBeforeReset(void)
-{
- return;
-}
-#endif
-
-void
-ddxUseMsg(void)
-{
- ErrorF("-screen scrn WxHxD set screen's width, height, depth\n");
- ErrorF("-pixdepths list-of-int support given pixmap depths\n");
- ErrorF("+/-render turn on/off RENDER extension support"
- "(default on)\n");
- ErrorF("-linebias n adjust thin line pixelization\n");
- ErrorF("-blackpixel n pixel value for black\n");
- ErrorF("-whitepixel n pixel value for white\n");
-
-#ifdef HAS_MMAP
- ErrorF("-fbdir directory put framebuffers in mmap'ed files in directory\n");
-#endif
-
-#ifdef HAS_SHM
- ErrorF("-shmem put framebuffers in shared memory\n");
-#endif
-}
-
-int
-ddxProcessArgument(int argc, char *argv[], int i)
-{
- static Bool firstTime = TRUE;
- static int lastScreen = -1;
- vfbScreenInfo *currentScreen;
-
- if (firstTime)
- {
- vfbInitializePixmapDepths();
- firstTime = FALSE;
- }
-
- if (lastScreen == -1)
- currentScreen = &defaultScreenInfo;
- else
- currentScreen = &vfbScreens[lastScreen];
-
-#define CHECK_FOR_REQUIRED_ARGUMENTS(num) \
- if (((i + num) >= argc) || (!argv[i + num])) { \
- ErrorF("Required argument to %s not specified\n", argv[i]); \
- UseMsg(); \
- FatalError("Required argument to %s not specified\n", argv[i]); \
- }
-
- if (strcmp (argv[i], "-screen") == 0) /* -screen n WxHxD */
- {
- int screenNum;
- CHECK_FOR_REQUIRED_ARGUMENTS(2);
- screenNum = atoi(argv[i+1]);
- if (screenNum < 0)
- {
- ErrorF("Invalid screen number %d\n", screenNum);
- UseMsg();
- FatalError("Invalid screen number %d passed to -screen\n",
- screenNum);
- }
-
- if (vfbNumScreens <= screenNum)
- {
- vfbScreens = realloc(vfbScreens, sizeof(*vfbScreens) * (screenNum + 1));
- if (!vfbScreens)
- FatalError("Not enough memory for screen %d\n", screenNum);
- for (; vfbNumScreens <= screenNum; ++vfbNumScreens)
- vfbScreens[vfbNumScreens] = defaultScreenInfo;
- }
-
- if (3 != sscanf(argv[i+2], "%dx%dx%d",
- &vfbScreens[screenNum].width,
- &vfbScreens[screenNum].height,
- &vfbScreens[screenNum].depth))
- {
- ErrorF("Invalid screen configuration %s\n", argv[i+2]);
- UseMsg();
- FatalError("Invalid screen configuration %s for -screen %d\n",
- argv[i+2], screenNum);
- }
-
- lastScreen = screenNum;
- return 3;
- }
-
- if (strcmp (argv[i], "-pixdepths") == 0) /* -pixdepths list-of-depth */
- {
- int depth, ret = 1;
-
- CHECK_FOR_REQUIRED_ARGUMENTS(1);
- while ((++i < argc) && (depth = atoi(argv[i])) != 0)
- {
- if (depth < 0 || depth > 32)
- {
- ErrorF("Invalid pixmap depth %d\n", depth);
- UseMsg();
- FatalError("Invalid pixmap depth %d passed to -pixdepths\n",
- depth);
- }
- vfbPixmapDepths[depth] = TRUE;
- ret++;
- }
- return ret;
- }
-
- if (strcmp (argv[i], "+render") == 0) /* +render */
- {
- Render = TRUE;
- return 1;
- }
-
- if (strcmp (argv[i], "-render") == 0) /* -render */
- {
- Render = FALSE;
-#ifdef COMPOSITE
- noCompositeExtension = TRUE;
-#endif
- return 1;
- }
-
- if (strcmp (argv[i], "-blackpixel") == 0) /* -blackpixel n */
- {
- CHECK_FOR_REQUIRED_ARGUMENTS(1);
- currentScreen->blackPixel = atoi(argv[++i]);
- return 2;
- }
-
- if (strcmp (argv[i], "-whitepixel") == 0) /* -whitepixel n */
- {
- CHECK_FOR_REQUIRED_ARGUMENTS(1);
- currentScreen->whitePixel = atoi(argv[++i]);
- return 2;
- }
-
- if (strcmp (argv[i], "-linebias") == 0) /* -linebias n */
- {
- CHECK_FOR_REQUIRED_ARGUMENTS(1);
- currentScreen->lineBias = atoi(argv[++i]);
- return 2;
- }
-
-#ifdef HAS_MMAP
- if (strcmp (argv[i], "-fbdir") == 0) /* -fbdir directory */
- {
- CHECK_FOR_REQUIRED_ARGUMENTS(1);
- pfbdir = argv[++i];
- fbmemtype = MMAPPED_FILE_FB;
- return 2;
- }
-#endif /* HAS_MMAP */
-
-#ifdef HAS_SHM
- if (strcmp (argv[i], "-shmem") == 0) /* -shmem */
- {
- fbmemtype = SHARED_MEMORY_FB;
- return 1;
- }
-#endif
-
- return 0;
-}
-
-static DevPrivateKeyRec cmapScrPrivateKeyRec;
-#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
-
-#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
-#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
-
-static int
-vfbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
-{
- /* By the time we are processing requests, we can guarantee that there
- * is always a colormap installed */
- *pmaps = GetInstalledColormap(pScreen)->mid;
- return 1;
-}
-
-
-static void
-vfbInstallColormap(ColormapPtr pmap)
-{
- ColormapPtr oldpmap = GetInstalledColormap(pmap->pScreen);
-
- if (pmap != oldpmap)
- {
- int entries;
- XWDFileHeader *pXWDHeader;
- XWDColor *pXWDCmap;
- VisualPtr pVisual;
- Pixel * ppix;
- xrgb * prgb;
- xColorItem *defs;
- int i;
-
- if(oldpmap != (ColormapPtr)None)
- WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
- /* Install pmap */
- SetInstalledColormap(pmap->pScreen, pmap);
- WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
-
- entries = pmap->pVisual->ColormapEntries;
- pXWDHeader = vfbScreens[pmap->pScreen->myNum].pXWDHeader;
- pXWDCmap = vfbScreens[pmap->pScreen->myNum].pXWDCmap;
- pVisual = pmap->pVisual;
-
- swapcopy32(pXWDHeader->visual_class, pVisual->class);
- swapcopy32(pXWDHeader->red_mask, pVisual->redMask);
- swapcopy32(pXWDHeader->green_mask, pVisual->greenMask);
- swapcopy32(pXWDHeader->blue_mask, pVisual->blueMask);
- swapcopy32(pXWDHeader->bits_per_rgb, pVisual->bitsPerRGBValue);
- swapcopy32(pXWDHeader->colormap_entries, pVisual->ColormapEntries);
-
- ppix = (Pixel *)malloc(entries * sizeof(Pixel));
- prgb = (xrgb *)malloc(entries * sizeof(xrgb));
- defs = (xColorItem *)malloc(entries * sizeof(xColorItem));
-
- for (i = 0; i < entries; i++) ppix[i] = i;
- /* XXX truecolor */
- QueryColors(pmap, entries, ppix, prgb, serverClient);
-
- for (i = 0; i < entries; i++) { /* convert xrgbs to xColorItems */
- defs[i].pixel = ppix[i] & 0xff; /* change pixel to index */
- defs[i].red = prgb[i].red;
- defs[i].green = prgb[i].green;
- defs[i].blue = prgb[i].blue;
- defs[i].flags = DoRed|DoGreen|DoBlue;
- }
- (*pmap->pScreen->StoreColors)(pmap, entries, defs);
-
- free(ppix);
- free(prgb);
- free(defs);
- }
-}
-
-static void
-vfbUninstallColormap(ColormapPtr pmap)
-{
- ColormapPtr curpmap = GetInstalledColormap(pmap->pScreen);
-
- if(pmap == curpmap)
- {
- if (pmap->mid != pmap->pScreen->defColormap)
- {
- dixLookupResourceByType((pointer *)&curpmap,
- pmap->pScreen->defColormap,
- RT_COLORMAP, serverClient,
- DixInstallAccess);
- (*pmap->pScreen->InstallColormap)(curpmap);
- }
- }
-}
-
-static void
-vfbStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs)
-{
- XWDColor *pXWDCmap;
- int i;
-
- if (pmap != GetInstalledColormap(pmap->pScreen))
- {
- return;
- }
-
- pXWDCmap = vfbScreens[pmap->pScreen->myNum].pXWDCmap;
-
- if ((pmap->pVisual->class | DynamicClass) == DirectColor)
- {
- return;
- }
-
- for (i = 0; i < ndef; i++)
- {
- if (pdefs[i].flags & DoRed)
- {
- swapcopy16(pXWDCmap[pdefs[i].pixel].red, pdefs[i].red);
- }
- if (pdefs[i].flags & DoGreen)
- {
- swapcopy16(pXWDCmap[pdefs[i].pixel].green, pdefs[i].green);
- }
- if (pdefs[i].flags & DoBlue)
- {
- swapcopy16(pXWDCmap[pdefs[i].pixel].blue, pdefs[i].blue);
- }
- }
-}
-
-static Bool
-vfbSaveScreen(ScreenPtr pScreen, int on)
-{
- return TRUE;
-}
-
-#ifdef HAS_MMAP
-
-/* this flushes any changes to the screens out to the mmapped file */
-static void
-vfbBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
-{
- int i;
-
- for (i = 0; i < vfbNumScreens; i++)
- {
-#ifdef MS_ASYNC
- if (-1 == msync((caddr_t)vfbScreens[i].pXWDHeader,
- (size_t)vfbScreens[i].sizeInBytes, MS_ASYNC))
-#else
- /* silly NetBSD and who else? */
- if (-1 == msync((caddr_t)vfbScreens[i].pXWDHeader,
- (size_t)vfbScreens[i].sizeInBytes))
-#endif
- {
- perror("msync");
- ErrorF("msync failed, %s", strerror(errno));
- }
- }
-}
-
-
-static void
-vfbWakeupHandler(pointer blockData, int result, pointer pReadmask)
-{
-}
-
-
-static void
-vfbAllocateMmappedFramebuffer(vfbScreenInfoPtr pvfb)
-{
-#define DUMMY_BUFFER_SIZE 65536
- char dummyBuffer[DUMMY_BUFFER_SIZE];
- int currentFileSize, writeThisTime;
-
- sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, (int) (pvfb - vfbScreens));
- if (-1 == (pvfb->mmap_fd = open(pvfb->mmap_file, O_CREAT|O_RDWR, 0666)))
- {
- perror("open");
- ErrorF("open %s failed, %s", pvfb->mmap_file, strerror(errno));
- return;
- }
-
- /* Extend the file to be the proper size */
-
- memset(dummyBuffer, 0, DUMMY_BUFFER_SIZE);
- for (currentFileSize = 0;
- currentFileSize < pvfb->sizeInBytes;
- currentFileSize += writeThisTime)
- {
- writeThisTime = min(DUMMY_BUFFER_SIZE,
- pvfb->sizeInBytes - currentFileSize);
- if (-1 == write(pvfb->mmap_fd, dummyBuffer, writeThisTime))
- {
- perror("write");
- ErrorF("write %s failed, %s", pvfb->mmap_file, strerror(errno));
- return;
- }
- }
-
- /* try to mmap the file */
-
- pvfb->pXWDHeader = (XWDFileHeader *)mmap((caddr_t)NULL, pvfb->sizeInBytes,
- PROT_READ|PROT_WRITE,
- MAP_FILE|MAP_SHARED,
- pvfb->mmap_fd, 0);
- if (-1 == (long)pvfb->pXWDHeader)
- {
- perror("mmap");
- ErrorF("mmap %s failed, %s", pvfb->mmap_file, strerror(errno));
- pvfb->pXWDHeader = NULL;
- return;
- }
-
- if (!RegisterBlockAndWakeupHandlers(vfbBlockHandler, vfbWakeupHandler,
- NULL))
- {
- pvfb->pXWDHeader = NULL;
- }
-}
-#endif /* HAS_MMAP */
-
-
-#ifdef HAS_SHM
-static void
-vfbAllocateSharedMemoryFramebuffer(vfbScreenInfoPtr pvfb)
-{
- /* create the shared memory segment */
-
- pvfb->shmid = shmget(IPC_PRIVATE, pvfb->sizeInBytes, IPC_CREAT|0777);
- if (pvfb->shmid < 0)
- {
- perror("shmget");
- ErrorF("shmget %d bytes failed, %s", pvfb->sizeInBytes, strerror(errno));
- return;
- }
-
- /* try to attach it */
-
- pvfb->pXWDHeader = (XWDFileHeader *)shmat(pvfb->shmid, 0, 0);
- if (-1 == (long)pvfb->pXWDHeader)
- {
- perror("shmat");
- ErrorF("shmat failed, %s", strerror(errno));
- pvfb->pXWDHeader = NULL;
- return;
- }
-
- ErrorF("screen %d shmid %d\n", (int) (pvfb - vfbScreens), pvfb->shmid);
-}
-#endif /* HAS_SHM */
-
-static char *
-vfbAllocateFramebufferMemory(vfbScreenInfoPtr pvfb)
-{
- if (pvfb->pfbMemory) return pvfb->pfbMemory; /* already done */
-
- pvfb->sizeInBytes = pvfb->paddedBytesWidth * pvfb->height;
-
- /* Calculate how many entries in colormap. This is rather bogus, because
- * the visuals haven't even been set up yet, but we need to know because we
- * have to allocate space in the file for the colormap. The number 10
- * below comes from the MAX_PSEUDO_DEPTH define in cfbcmap.c.
- */
-
- if (pvfb->depth <= 10)
- { /* single index colormaps */
- pvfb->ncolors = 1 << pvfb->depth;
- }
- else
- { /* decomposed colormaps */
- int nplanes_per_color_component = pvfb->depth / 3;
- if (pvfb->depth % 3) nplanes_per_color_component++;
- pvfb->ncolors = 1 << nplanes_per_color_component;
- }
-
- /* add extra bytes for XWDFileHeader, window name, and colormap */
-
- pvfb->sizeInBytes += SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN +
- pvfb->ncolors * SIZEOF(XWDColor);
-
- pvfb->pXWDHeader = NULL;
- switch (fbmemtype)
- {
-#ifdef HAS_MMAP
- case MMAPPED_FILE_FB: vfbAllocateMmappedFramebuffer(pvfb); break;
-#else
- case MMAPPED_FILE_FB: break;
-#endif
-
-#ifdef HAS_SHM
- case SHARED_MEMORY_FB: vfbAllocateSharedMemoryFramebuffer(pvfb); break;
-#else
- case SHARED_MEMORY_FB: break;
-#endif
-
- case NORMAL_MEMORY_FB:
- pvfb->pXWDHeader = (XWDFileHeader *)malloc(pvfb->sizeInBytes);
- break;
- }
-
- if (pvfb->pXWDHeader)
- {
- pvfb->pXWDCmap = (XWDColor *)((char *)pvfb->pXWDHeader
- + SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN);
- pvfb->pfbMemory = (char *)(pvfb->pXWDCmap + pvfb->ncolors);
-
- return pvfb->pfbMemory;
- }
- else
- return NULL;
-}
-
-
-static void
-vfbWriteXWDFileHeader(ScreenPtr pScreen)
-{
- vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
- XWDFileHeader *pXWDHeader = pvfb->pXWDHeader;
- char hostname[XWD_WINDOW_NAME_LEN];
- unsigned long swaptest = 1;
- int i;
-
- needswap = *(char *) &swaptest;
-
- pXWDHeader->header_size = (char *)pvfb->pXWDCmap - (char *)pvfb->pXWDHeader;
- pXWDHeader->file_version = XWD_FILE_VERSION;
-
- pXWDHeader->pixmap_format = ZPixmap;
- pXWDHeader->pixmap_depth = pvfb->depth;
- pXWDHeader->pixmap_height = pXWDHeader->window_height = pvfb->height;
- pXWDHeader->xoffset = 0;
- pXWDHeader->byte_order = IMAGE_BYTE_ORDER;
- pXWDHeader->bitmap_bit_order = BITMAP_BIT_ORDER;
-#ifndef INTERNAL_VS_EXTERNAL_PADDING
- pXWDHeader->pixmap_width = pXWDHeader->window_width = pvfb->width;
- pXWDHeader->bitmap_unit = BITMAP_SCANLINE_UNIT;
- pXWDHeader->bitmap_pad = BITMAP_SCANLINE_PAD;
-#else
- pXWDHeader->pixmap_width = pXWDHeader->window_width = pvfb->paddedWidth;
- pXWDHeader->bitmap_unit = BITMAP_SCANLINE_UNIT_PROTO;
- pXWDHeader->bitmap_pad = BITMAP_SCANLINE_PAD_PROTO;
-#endif
- pXWDHeader->bits_per_pixel = pvfb->bitsPerPixel;
- pXWDHeader->bytes_per_line = pvfb->paddedBytesWidth;
- pXWDHeader->ncolors = pvfb->ncolors;
-
- /* visual related fields are written when colormap is installed */
-
- pXWDHeader->window_x = pXWDHeader->window_y = 0;
- pXWDHeader->window_bdrwidth = 0;
-
- /* write xwd "window" name: Xvfb hostname:server.screen */
-
- if (-1 == gethostname(hostname, sizeof(hostname)))
- hostname[0] = 0;
- else
- hostname[XWD_WINDOW_NAME_LEN-1] = 0;
- sprintf((char *)(pXWDHeader+1), "Xvfb %s:%s.%d", hostname, display,
- pScreen->myNum);
-
- /* write colormap pixel slot values */
-
- for (i = 0; i < pvfb->ncolors; i++)
- {
- pvfb->pXWDCmap[i].pixel = i;
- }
-
- /* byte swap to most significant byte first */
-
- if (needswap)
- {
- SwapLongs((CARD32 *)pXWDHeader, SIZEOF(XWDheader)/4);
- for (i = 0; i < pvfb->ncolors; i++)
- {
- register char n;
- swapl(&pvfb->pXWDCmap[i].pixel, n);
- }
- }
-}
-
-
-static Bool
-vfbCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y)
-{
- return FALSE;
-}
-
-static void
-vfbCrossScreen (ScreenPtr pScreen, Bool entering)
-{
-}
-
-static miPointerScreenFuncRec vfbPointerCursorFuncs =
-{
- vfbCursorOffScreen,
- vfbCrossScreen,
- miPointerWarpCursor
-};
-
-static Bool
-vfbCloseScreen(int index, ScreenPtr pScreen)
-{
- vfbScreenInfoPtr pvfb = &vfbScreens[index];
- int i;
-
- pScreen->CloseScreen = pvfb->closeScreen;
-
- /*
- * XXX probably lots of stuff to clean. For now,
- * clear installed colormaps so that server reset works correctly.
- */
- for (i = 0; i < screenInfo.numScreens; i++)
- SetInstalledColormap(screenInfo.screens[i], NULL);
-
- return pScreen->CloseScreen(index, pScreen);
-}
-
-static Bool
-vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
-{
- vfbScreenInfoPtr pvfb = &vfbScreens[index];
- int dpix = monitorResolution, dpiy = monitorResolution;
- int ret;
- char *pbits;
-
- if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
- return FALSE;
-
- if (dpix == 0)
- dpix = 100;
-
- if (dpiy == 0)
- dpiy = 100;
-
- pvfb->paddedBytesWidth = PixmapBytePad(pvfb->width, pvfb->depth);
- pvfb->bitsPerPixel = vfbBitsPerPixel(pvfb->depth);
- if (pvfb->bitsPerPixel >= 8 )
- pvfb->paddedWidth = pvfb->paddedBytesWidth / (pvfb->bitsPerPixel / 8);
- else
- pvfb->paddedWidth = pvfb->paddedBytesWidth * 8;
- pbits = vfbAllocateFramebufferMemory(pvfb);
- if (!pbits) return FALSE;
-
- switch (pvfb->depth) {
- case 8:
- miSetVisualTypesAndMasks (8,
- ((1 << StaticGray) |
- (1 << GrayScale) |
- (1 << StaticColor) |
- (1 << PseudoColor) |
- (1 << TrueColor) |
- (1 << DirectColor)),
- 8, PseudoColor, 0, 0, 0);
- break;
- case 15:
- miSetVisualTypesAndMasks (15,
- ((1 << TrueColor) |
- (1 << DirectColor)),
- 8, TrueColor, 0x7c00, 0x03e0, 0x001f);
- break;
- case 16:
- miSetVisualTypesAndMasks (16,
- ((1 << TrueColor) |
- (1 << DirectColor)),
- 8, TrueColor, 0xf800, 0x07e0, 0x001f);
- break;
- case 24:
- miSetVisualTypesAndMasks (24,
- ((1 << TrueColor) |
- (1 << DirectColor)),
- 8, TrueColor, 0xff0000, 0x00ff00, 0x0000ff);
- break;
- case 30:
- miSetVisualTypesAndMasks (30,
- ((1 << TrueColor) |
- (1 << DirectColor)),
- 10, TrueColor, 0x3ff00000, 0x000ffc00, 0x000003ff);
- break;
- }
-
- miSetPixmapDepths ();
-
- ret = fbScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
- dpix, dpiy, pvfb->paddedWidth,pvfb->bitsPerPixel);
- if (ret && Render)
- fbPictureInit (pScreen, 0, 0);
-
- if (!ret) return FALSE;
-
- pScreen->InstallColormap = vfbInstallColormap;
- pScreen->UninstallColormap = vfbUninstallColormap;
- pScreen->ListInstalledColormaps = vfbListInstalledColormaps;
-
- pScreen->SaveScreen = vfbSaveScreen;
- pScreen->StoreColors = vfbStoreColors;
-
- miDCInitialize(pScreen, &vfbPointerCursorFuncs);
-
- vfbWriteXWDFileHeader(pScreen);
-
- pScreen->blackPixel = pvfb->blackPixel;
- pScreen->whitePixel = pvfb->whitePixel;
-
- ret = fbCreateDefColormap(pScreen);
-
- miSetZeroLineBias(pScreen, pvfb->lineBias);
-
- pvfb->closeScreen = pScreen->CloseScreen;
- pScreen->CloseScreen = vfbCloseScreen;
-
- return ret;
-
-} /* end vfbScreenInit */
-
-
-void
-InitOutput(ScreenInfo *screenInfo, int argc, char **argv)
-{
- int i;
- int NumFormats = 0;
-
- /* initialize pixmap formats */
-
- /* must have a pixmap depth to match every screen depth */
- for (i = 0; i < vfbNumScreens; i++)
- {
- vfbPixmapDepths[vfbScreens[i].depth] = TRUE;
- }
-
- /* RENDER needs a good set of pixmaps. */
- if (Render) {
- vfbPixmapDepths[1] = TRUE;
- vfbPixmapDepths[4] = TRUE;
- vfbPixmapDepths[8] = TRUE;
-#if 0
- vfbPixmapDepths[12] = TRUE;
-#endif
-/* vfbPixmapDepths[15] = TRUE; */
- vfbPixmapDepths[16] = TRUE;
- vfbPixmapDepths[24] = TRUE;
-#if 0
- vfbPixmapDepths[30] = TRUE;
-#endif
- vfbPixmapDepths[32] = TRUE;
- }
-
- for (i = 1; i <= 32; i++)
- {
- if (vfbPixmapDepths[i])
- {
- if (NumFormats >= MAXFORMATS)
- FatalError ("MAXFORMATS is too small for this server\n");
- screenInfo->formats[NumFormats].depth = i;
- screenInfo->formats[NumFormats].bitsPerPixel = vfbBitsPerPixel(i);
- screenInfo->formats[NumFormats].scanlinePad = BITMAP_SCANLINE_PAD;
- NumFormats++;
- }
- }
-
- screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
- screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
- screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
- screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
- screenInfo->numPixmapFormats = NumFormats;
-
- /* initialize screens */
-
- if (vfbNumScreens < 1)
- {
- vfbScreens = &defaultScreenInfo;
- vfbNumScreens = 1;
- }
- for (i = 0; i < vfbNumScreens; i++)
- {
- if (-1 == AddScreen(vfbScreenInit, argc, argv))
- {
- FatalError("Couldn't add screen %d", i);
- }
- }
-
-} /* end InitOutput */
+/*
+
+Copyright 1993, 1998 The Open Group
+
+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.
+
+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 OPEN GROUP 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 Open Group 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 Open Group.
+
+*/
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#if defined(WIN32)
+#include <X11/Xwinsock.h>
+#endif
+#include <stdio.h>
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/Xos.h>
+#include "scrnintstr.h"
+#include "servermd.h"
+#define PSZ 8
+#include "fb.h"
+#include "mibstore.h"
+#include "colormapst.h"
+#include "gcstruct.h"
+#include "input.h"
+#include "mipointer.h"
+#include "micmap.h"
+#include <sys/types.h>
+#ifdef HAS_MMAP
+#include <sys/mman.h>
+#ifndef MAP_FILE
+#define MAP_FILE 0
+#endif
+#endif /* HAS_MMAP */
+#include <sys/stat.h>
+#include <errno.h>
+#ifndef WIN32
+#include <sys/param.h>
+#endif
+#include <X11/XWDFile.h>
+#ifdef HAS_SHM
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#endif /* HAS_SHM */
+#include "dix.h"
+#include "miline.h"
+
+#define VFB_DEFAULT_WIDTH 1280
+#define VFB_DEFAULT_HEIGHT 1024
+#define VFB_DEFAULT_DEPTH 8
+#define VFB_DEFAULT_WHITEPIXEL 1
+#define VFB_DEFAULT_BLACKPIXEL 0
+#define VFB_DEFAULT_LINEBIAS 0
+#define XWD_WINDOW_NAME_LEN 60
+
+typedef struct
+{
+ int width;
+ int paddedBytesWidth;
+ int paddedWidth;
+ int height;
+ int depth;
+ int bitsPerPixel;
+ int sizeInBytes;
+ int ncolors;
+ char *pfbMemory;
+ XWDColor *pXWDCmap;
+ XWDFileHeader *pXWDHeader;
+ Pixel blackPixel;
+ Pixel whitePixel;
+ unsigned int lineBias;
+ CloseScreenProcPtr closeScreen;
+
+#ifdef HAS_MMAP
+ int mmap_fd;
+ char mmap_file[MAXPATHLEN];
+#endif
+
+#ifdef HAS_SHM
+ int shmid;
+#endif
+} vfbScreenInfo, *vfbScreenInfoPtr;
+
+static int vfbNumScreens;
+static vfbScreenInfo *vfbScreens;
+static vfbScreenInfo defaultScreenInfo = {
+ .width = VFB_DEFAULT_WIDTH,
+ .height = VFB_DEFAULT_HEIGHT,
+ .depth = VFB_DEFAULT_DEPTH,
+ .blackPixel = VFB_DEFAULT_BLACKPIXEL,
+ .whitePixel = VFB_DEFAULT_WHITEPIXEL,
+ .lineBias = VFB_DEFAULT_LINEBIAS,
+};
+static Bool vfbPixmapDepths[33];
+#ifdef HAS_MMAP
+static char *pfbdir = NULL;
+#endif
+typedef enum { NORMAL_MEMORY_FB, SHARED_MEMORY_FB, MMAPPED_FILE_FB } fbMemType;
+static fbMemType fbmemtype = NORMAL_MEMORY_FB;
+static char needswap = 0;
+static Bool Render = TRUE;
+
+#define swapcopy16(_dst, _src) \
+ if (needswap) { CARD16 _s = _src; cpswaps(_s, _dst); } \
+ else _dst = _src;
+
+#define swapcopy32(_dst, _src) \
+ if (needswap) { CARD32 _s = _src; cpswapl(_s, _dst); } \
+ else _dst = _src;
+
+
+static void
+vfbInitializePixmapDepths(void)
+{
+ int i;
+ vfbPixmapDepths[1] = TRUE; /* always need bitmaps */
+ for (i = 2; i <= 32; i++)
+ vfbPixmapDepths[i] = FALSE;
+}
+
+static int
+vfbBitsPerPixel(int depth)
+{
+ if (depth == 1) return 1;
+ else if (depth <= 8) return 8;
+ else if (depth <= 16) return 16;
+ else return 32;
+}
+
+void
+ddxGiveUp(enum ExitCode error)
+{
+ int i;
+
+ /* clean up the framebuffers */
+
+ switch (fbmemtype)
+ {
+#ifdef HAS_MMAP
+ case MMAPPED_FILE_FB:
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ if (-1 == unlink(vfbScreens[i].mmap_file))
+ {
+ perror("unlink");
+ ErrorF("unlink %s failed, %s",
+ vfbScreens[i].mmap_file, strerror(errno));
+ }
+ }
+ break;
+#else /* HAS_MMAP */
+ case MMAPPED_FILE_FB:
+ break;
+#endif /* HAS_MMAP */
+
+#ifdef HAS_SHM
+ case SHARED_MEMORY_FB:
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ if (-1 == shmdt((char *)vfbScreens[i].pXWDHeader))
+ {
+ perror("shmdt");
+ ErrorF("shmdt failed, %s", strerror(errno));
+ }
+ }
+ break;
+#else /* HAS_SHM */
+ case SHARED_MEMORY_FB:
+ break;
+#endif /* HAS_SHM */
+
+ case NORMAL_MEMORY_FB:
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ free(vfbScreens[i].pXWDHeader);
+ }
+ break;
+ }
+}
+
+void
+AbortDDX(enum ExitCode error)
+{
+ ddxGiveUp(error);
+}
+
+#ifdef __APPLE__
+void
+DarwinHandleGUI(int argc, char *argv[])
+{
+}
+#endif
+
+void
+OsVendorInit(void)
+{
+}
+
+void
+OsVendorFatalError(void)
+{
+}
+
+#if defined(DDXBEFORERESET)
+void ddxBeforeReset(void)
+{
+ return;
+}
+#endif
+
+void
+ddxUseMsg(void)
+{
+ ErrorF("-screen scrn WxHxD set screen's width, height, depth\n");
+ ErrorF("-pixdepths list-of-int support given pixmap depths\n");
+ ErrorF("+/-render turn on/off RENDER extension support"
+ "(default on)\n");
+ ErrorF("-linebias n adjust thin line pixelization\n");
+ ErrorF("-blackpixel n pixel value for black\n");
+ ErrorF("-whitepixel n pixel value for white\n");
+
+#ifdef HAS_MMAP
+ ErrorF("-fbdir directory put framebuffers in mmap'ed files in directory\n");
+#endif
+
+#ifdef HAS_SHM
+ ErrorF("-shmem put framebuffers in shared memory\n");
+#endif
+}
+
+int
+ddxProcessArgument(int argc, char *argv[], int i)
+{
+ static Bool firstTime = TRUE;
+ static int lastScreen = -1;
+ vfbScreenInfo *currentScreen;
+
+ if (firstTime)
+ {
+ vfbInitializePixmapDepths();
+ firstTime = FALSE;
+ }
+
+ if (lastScreen == -1)
+ currentScreen = &defaultScreenInfo;
+ else
+ currentScreen = &vfbScreens[lastScreen];
+
+#define CHECK_FOR_REQUIRED_ARGUMENTS(num) \
+ if (((i + num) >= argc) || (!argv[i + num])) { \
+ ErrorF("Required argument to %s not specified\n", argv[i]); \
+ UseMsg(); \
+ FatalError("Required argument to %s not specified\n", argv[i]); \
+ }
+
+ if (strcmp (argv[i], "-screen") == 0) /* -screen n WxHxD */
+ {
+ int screenNum;
+ CHECK_FOR_REQUIRED_ARGUMENTS(2);
+ screenNum = atoi(argv[i+1]);
+ if (screenNum < 0)
+ {
+ ErrorF("Invalid screen number %d\n", screenNum);
+ UseMsg();
+ FatalError("Invalid screen number %d passed to -screen\n",
+ screenNum);
+ }
+
+ if (vfbNumScreens <= screenNum)
+ {
+ vfbScreens = realloc(vfbScreens, sizeof(*vfbScreens) * (screenNum + 1));
+ if (!vfbScreens)
+ FatalError("Not enough memory for screen %d\n", screenNum);
+ for (; vfbNumScreens <= screenNum; ++vfbNumScreens)
+ vfbScreens[vfbNumScreens] = defaultScreenInfo;
+ }
+
+ if (3 != sscanf(argv[i+2], "%dx%dx%d",
+ &vfbScreens[screenNum].width,
+ &vfbScreens[screenNum].height,
+ &vfbScreens[screenNum].depth))
+ {
+ ErrorF("Invalid screen configuration %s\n", argv[i+2]);
+ UseMsg();
+ FatalError("Invalid screen configuration %s for -screen %d\n",
+ argv[i+2], screenNum);
+ }
+
+ lastScreen = screenNum;
+ return 3;
+ }
+
+ if (strcmp (argv[i], "-pixdepths") == 0) /* -pixdepths list-of-depth */
+ {
+ int depth, ret = 1;
+
+ CHECK_FOR_REQUIRED_ARGUMENTS(1);
+ while ((++i < argc) && (depth = atoi(argv[i])) != 0)
+ {
+ if (depth < 0 || depth > 32)
+ {
+ ErrorF("Invalid pixmap depth %d\n", depth);
+ UseMsg();
+ FatalError("Invalid pixmap depth %d passed to -pixdepths\n",
+ depth);
+ }
+ vfbPixmapDepths[depth] = TRUE;
+ ret++;
+ }
+ return ret;
+ }
+
+ if (strcmp (argv[i], "+render") == 0) /* +render */
+ {
+ Render = TRUE;
+ return 1;
+ }
+
+ if (strcmp (argv[i], "-render") == 0) /* -render */
+ {
+ Render = FALSE;
+#ifdef COMPOSITE
+ noCompositeExtension = TRUE;
+#endif
+ return 1;
+ }
+
+ if (strcmp (argv[i], "-blackpixel") == 0) /* -blackpixel n */
+ {
+ CHECK_FOR_REQUIRED_ARGUMENTS(1);
+ currentScreen->blackPixel = atoi(argv[++i]);
+ return 2;
+ }
+
+ if (strcmp (argv[i], "-whitepixel") == 0) /* -whitepixel n */
+ {
+ CHECK_FOR_REQUIRED_ARGUMENTS(1);
+ currentScreen->whitePixel = atoi(argv[++i]);
+ return 2;
+ }
+
+ if (strcmp (argv[i], "-linebias") == 0) /* -linebias n */
+ {
+ CHECK_FOR_REQUIRED_ARGUMENTS(1);
+ currentScreen->lineBias = atoi(argv[++i]);
+ return 2;
+ }
+
+#ifdef HAS_MMAP
+ if (strcmp (argv[i], "-fbdir") == 0) /* -fbdir directory */
+ {
+ CHECK_FOR_REQUIRED_ARGUMENTS(1);
+ pfbdir = argv[++i];
+ fbmemtype = MMAPPED_FILE_FB;
+ return 2;
+ }
+#endif /* HAS_MMAP */
+
+#ifdef HAS_SHM
+ if (strcmp (argv[i], "-shmem") == 0) /* -shmem */
+ {
+ fbmemtype = SHARED_MEMORY_FB;
+ return 1;
+ }
+#endif
+
+ return 0;
+}
+
+static DevPrivateKeyRec cmapScrPrivateKeyRec;
+#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
+
+#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
+#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
+
+static int
+vfbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
+{
+ /* By the time we are processing requests, we can guarantee that there
+ * is always a colormap installed */
+ *pmaps = GetInstalledColormap(pScreen)->mid;
+ return 1;
+}
+
+
+static void
+vfbInstallColormap(ColormapPtr pmap)
+{
+ ColormapPtr oldpmap = GetInstalledColormap(pmap->pScreen);
+
+ if (pmap != oldpmap)
+ {
+ int entries;
+ XWDFileHeader *pXWDHeader;
+ XWDColor *pXWDCmap;
+ VisualPtr pVisual;
+ Pixel * ppix;
+ xrgb * prgb;
+ xColorItem *defs;
+ int i;
+
+ if(oldpmap != (ColormapPtr)None)
+ WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
+ /* Install pmap */
+ SetInstalledColormap(pmap->pScreen, pmap);
+ WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
+
+ entries = pmap->pVisual->ColormapEntries;
+ pXWDHeader = vfbScreens[pmap->pScreen->myNum].pXWDHeader;
+ pXWDCmap = vfbScreens[pmap->pScreen->myNum].pXWDCmap;
+ pVisual = pmap->pVisual;
+
+ swapcopy32(pXWDHeader->visual_class, pVisual->class);
+ swapcopy32(pXWDHeader->red_mask, pVisual->redMask);
+ swapcopy32(pXWDHeader->green_mask, pVisual->greenMask);
+ swapcopy32(pXWDHeader->blue_mask, pVisual->blueMask);
+ swapcopy32(pXWDHeader->bits_per_rgb, pVisual->bitsPerRGBValue);
+ swapcopy32(pXWDHeader->colormap_entries, pVisual->ColormapEntries);
+
+ ppix = (Pixel *)malloc(entries * sizeof(Pixel));
+ prgb = (xrgb *)malloc(entries * sizeof(xrgb));
+ defs = (xColorItem *)malloc(entries * sizeof(xColorItem));
+
+ for (i = 0; i < entries; i++) ppix[i] = i;
+ /* XXX truecolor */
+ QueryColors(pmap, entries, ppix, prgb, serverClient);
+
+ for (i = 0; i < entries; i++) { /* convert xrgbs to xColorItems */
+ defs[i].pixel = ppix[i] & 0xff; /* change pixel to index */
+ defs[i].red = prgb[i].red;
+ defs[i].green = prgb[i].green;
+ defs[i].blue = prgb[i].blue;
+ defs[i].flags = DoRed|DoGreen|DoBlue;
+ }
+ (*pmap->pScreen->StoreColors)(pmap, entries, defs);
+
+ free(ppix);
+ free(prgb);
+ free(defs);
+ }
+}
+
+static void
+vfbUninstallColormap(ColormapPtr pmap)
+{
+ ColormapPtr curpmap = GetInstalledColormap(pmap->pScreen);
+
+ if(pmap == curpmap)
+ {
+ if (pmap->mid != pmap->pScreen->defColormap)
+ {
+ dixLookupResourceByType((pointer *)&curpmap,
+ pmap->pScreen->defColormap,
+ RT_COLORMAP, serverClient,
+ DixInstallAccess);
+ (*pmap->pScreen->InstallColormap)(curpmap);
+ }
+ }
+}
+
+static void
+vfbStoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs)
+{
+ XWDColor *pXWDCmap;
+ int i;
+
+ if (pmap != GetInstalledColormap(pmap->pScreen))
+ {
+ return;
+ }
+
+ pXWDCmap = vfbScreens[pmap->pScreen->myNum].pXWDCmap;
+
+ if ((pmap->pVisual->class | DynamicClass) == DirectColor)
+ {
+ return;
+ }
+
+ for (i = 0; i < ndef; i++)
+ {
+ if (pdefs[i].flags & DoRed)
+ {
+ swapcopy16(pXWDCmap[pdefs[i].pixel].red, pdefs[i].red);
+ }
+ if (pdefs[i].flags & DoGreen)
+ {
+ swapcopy16(pXWDCmap[pdefs[i].pixel].green, pdefs[i].green);
+ }
+ if (pdefs[i].flags & DoBlue)
+ {
+ swapcopy16(pXWDCmap[pdefs[i].pixel].blue, pdefs[i].blue);
+ }
+ }
+}
+
+static Bool
+vfbSaveScreen(ScreenPtr pScreen, int on)
+{
+ return TRUE;
+}
+
+#ifdef HAS_MMAP
+
+/* this flushes any changes to the screens out to the mmapped file */
+static void
+vfbBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
+{
+ int i;
+
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+#ifdef MS_ASYNC
+ if (-1 == msync((caddr_t)vfbScreens[i].pXWDHeader,
+ (size_t)vfbScreens[i].sizeInBytes, MS_ASYNC))
+#else
+ /* silly NetBSD and who else? */
+ if (-1 == msync((caddr_t)vfbScreens[i].pXWDHeader,
+ (size_t)vfbScreens[i].sizeInBytes))
+#endif
+ {
+ perror("msync");
+ ErrorF("msync failed, %s", strerror(errno));
+ }
+ }
+}
+
+
+static void
+vfbWakeupHandler(pointer blockData, int result, pointer pReadmask)
+{
+}
+
+
+static void
+vfbAllocateMmappedFramebuffer(vfbScreenInfoPtr pvfb)
+{
+#define DUMMY_BUFFER_SIZE 65536
+ char dummyBuffer[DUMMY_BUFFER_SIZE];
+ int currentFileSize, writeThisTime;
+
+ sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, (int) (pvfb - vfbScreens));
+ if (-1 == (pvfb->mmap_fd = open(pvfb->mmap_file, O_CREAT|O_RDWR, 0666)))
+ {
+ perror("open");
+ ErrorF("open %s failed, %s", pvfb->mmap_file, strerror(errno));
+ return;
+ }
+
+ /* Extend the file to be the proper size */
+
+ memset(dummyBuffer, 0, DUMMY_BUFFER_SIZE);
+ for (currentFileSize = 0;
+ currentFileSize < pvfb->sizeInBytes;
+ currentFileSize += writeThisTime)
+ {
+ writeThisTime = min(DUMMY_BUFFER_SIZE,
+ pvfb->sizeInBytes - currentFileSize);
+ if (-1 == write(pvfb->mmap_fd, dummyBuffer, writeThisTime))
+ {
+ perror("write");
+ ErrorF("write %s failed, %s", pvfb->mmap_file, strerror(errno));
+ return;
+ }
+ }
+
+ /* try to mmap the file */
+
+ pvfb->pXWDHeader = (XWDFileHeader *)mmap((caddr_t)NULL, pvfb->sizeInBytes,
+ PROT_READ|PROT_WRITE,
+ MAP_FILE|MAP_SHARED,
+ pvfb->mmap_fd, 0);
+ if (-1 == (long)pvfb->pXWDHeader)
+ {
+ perror("mmap");
+ ErrorF("mmap %s failed, %s", pvfb->mmap_file, strerror(errno));
+ pvfb->pXWDHeader = NULL;
+ return;
+ }
+
+ if (!RegisterBlockAndWakeupHandlers(vfbBlockHandler, vfbWakeupHandler,
+ NULL))
+ {
+ pvfb->pXWDHeader = NULL;
+ }
+}
+#endif /* HAS_MMAP */
+
+
+#ifdef HAS_SHM
+static void
+vfbAllocateSharedMemoryFramebuffer(vfbScreenInfoPtr pvfb)
+{
+ /* create the shared memory segment */
+
+ pvfb->shmid = shmget(IPC_PRIVATE, pvfb->sizeInBytes, IPC_CREAT|0777);
+ if (pvfb->shmid < 0)
+ {
+ perror("shmget");
+ ErrorF("shmget %d bytes failed, %s", pvfb->sizeInBytes, strerror(errno));
+ return;
+ }
+
+ /* try to attach it */
+
+ pvfb->pXWDHeader = (XWDFileHeader *)shmat(pvfb->shmid, 0, 0);
+ if (-1 == (long)pvfb->pXWDHeader)
+ {
+ perror("shmat");
+ ErrorF("shmat failed, %s", strerror(errno));
+ pvfb->pXWDHeader = NULL;
+ return;
+ }
+
+ ErrorF("screen %d shmid %d\n", (int) (pvfb - vfbScreens), pvfb->shmid);
+}
+#endif /* HAS_SHM */
+
+static char *
+vfbAllocateFramebufferMemory(vfbScreenInfoPtr pvfb)
+{
+ if (pvfb->pfbMemory) return pvfb->pfbMemory; /* already done */
+
+ pvfb->sizeInBytes = pvfb->paddedBytesWidth * pvfb->height;
+
+ /* Calculate how many entries in colormap. This is rather bogus, because
+ * the visuals haven't even been set up yet, but we need to know because we
+ * have to allocate space in the file for the colormap. The number 10
+ * below comes from the MAX_PSEUDO_DEPTH define in cfbcmap.c.
+ */
+
+ if (pvfb->depth <= 10)
+ { /* single index colormaps */
+ pvfb->ncolors = 1 << pvfb->depth;
+ }
+ else
+ { /* decomposed colormaps */
+ int nplanes_per_color_component = pvfb->depth / 3;
+ if (pvfb->depth % 3) nplanes_per_color_component++;
+ pvfb->ncolors = 1 << nplanes_per_color_component;
+ }
+
+ /* add extra bytes for XWDFileHeader, window name, and colormap */
+
+ pvfb->sizeInBytes += SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN +
+ pvfb->ncolors * SIZEOF(XWDColor);
+
+ pvfb->pXWDHeader = NULL;
+ switch (fbmemtype)
+ {
+#ifdef HAS_MMAP
+ case MMAPPED_FILE_FB: vfbAllocateMmappedFramebuffer(pvfb); break;
+#else
+ case MMAPPED_FILE_FB: break;
+#endif
+
+#ifdef HAS_SHM
+ case SHARED_MEMORY_FB: vfbAllocateSharedMemoryFramebuffer(pvfb); break;
+#else
+ case SHARED_MEMORY_FB: break;
+#endif
+
+ case NORMAL_MEMORY_FB:
+ pvfb->pXWDHeader = (XWDFileHeader *)malloc(pvfb->sizeInBytes);
+ break;
+ }
+
+ if (pvfb->pXWDHeader)
+ {
+ pvfb->pXWDCmap = (XWDColor *)((char *)pvfb->pXWDHeader
+ + SIZEOF(XWDheader) + XWD_WINDOW_NAME_LEN);
+ pvfb->pfbMemory = (char *)(pvfb->pXWDCmap + pvfb->ncolors);
+
+ return pvfb->pfbMemory;
+ }
+ else
+ return NULL;
+}
+
+
+static void
+vfbWriteXWDFileHeader(ScreenPtr pScreen)
+{
+ vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
+ XWDFileHeader *pXWDHeader = pvfb->pXWDHeader;
+ char hostname[XWD_WINDOW_NAME_LEN];
+ unsigned long swaptest = 1;
+ int i;
+
+ needswap = *(char *) &swaptest;
+
+ pXWDHeader->header_size = (char *)pvfb->pXWDCmap - (char *)pvfb->pXWDHeader;
+ pXWDHeader->file_version = XWD_FILE_VERSION;
+
+ pXWDHeader->pixmap_format = ZPixmap;
+ pXWDHeader->pixmap_depth = pvfb->depth;
+ pXWDHeader->pixmap_height = pXWDHeader->window_height = pvfb->height;
+ pXWDHeader->xoffset = 0;
+ pXWDHeader->byte_order = IMAGE_BYTE_ORDER;
+ pXWDHeader->bitmap_bit_order = BITMAP_BIT_ORDER;
+#ifndef INTERNAL_VS_EXTERNAL_PADDING
+ pXWDHeader->pixmap_width = pXWDHeader->window_width = pvfb->width;
+ pXWDHeader->bitmap_unit = BITMAP_SCANLINE_UNIT;
+ pXWDHeader->bitmap_pad = BITMAP_SCANLINE_PAD;
+#else
+ pXWDHeader->pixmap_width = pXWDHeader->window_width = pvfb->paddedWidth;
+ pXWDHeader->bitmap_unit = BITMAP_SCANLINE_UNIT_PROTO;
+ pXWDHeader->bitmap_pad = BITMAP_SCANLINE_PAD_PROTO;
+#endif
+ pXWDHeader->bits_per_pixel = pvfb->bitsPerPixel;
+ pXWDHeader->bytes_per_line = pvfb->paddedBytesWidth;
+ pXWDHeader->ncolors = pvfb->ncolors;
+
+ /* visual related fields are written when colormap is installed */
+
+ pXWDHeader->window_x = pXWDHeader->window_y = 0;
+ pXWDHeader->window_bdrwidth = 0;
+
+ /* write xwd "window" name: Xvfb hostname:server.screen */
+
+ if (-1 == gethostname(hostname, sizeof(hostname)))
+ hostname[0] = 0;
+ else
+ hostname[XWD_WINDOW_NAME_LEN-1] = 0;
+ sprintf((char *)(pXWDHeader+1), "Xvfb %s:%s.%d", hostname, display,
+ pScreen->myNum);
+
+ /* write colormap pixel slot values */
+
+ for (i = 0; i < pvfb->ncolors; i++)
+ {
+ pvfb->pXWDCmap[i].pixel = i;
+ }
+
+ /* byte swap to most significant byte first */
+
+ if (needswap)
+ {
+ SwapLongs((CARD32 *)pXWDHeader, SIZEOF(XWDheader)/4);
+ for (i = 0; i < pvfb->ncolors; i++)
+ {
+ register char n;
+ swapl(&pvfb->pXWDCmap[i].pixel, n);
+ }
+ }
+}
+
+
+static Bool
+vfbCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y)
+{
+ return FALSE;
+}
+
+static void
+vfbCrossScreen (ScreenPtr pScreen, Bool entering)
+{
+}
+
+static miPointerScreenFuncRec vfbPointerCursorFuncs =
+{
+ vfbCursorOffScreen,
+ vfbCrossScreen,
+ miPointerWarpCursor
+};
+
+static Bool
+vfbCloseScreen(int index, ScreenPtr pScreen)
+{
+ vfbScreenInfoPtr pvfb = &vfbScreens[index];
+ int i;
+
+ pScreen->CloseScreen = pvfb->closeScreen;
+
+ /*
+ * XXX probably lots of stuff to clean. For now,
+ * clear installed colormaps so that server reset works correctly.
+ */
+ for (i = 0; i < screenInfo.numScreens; i++)
+ SetInstalledColormap(screenInfo.screens[i], NULL);
+
+ return pScreen->CloseScreen(index, pScreen);
+}
+
+static Bool
+vfbScreenInit(int index, ScreenPtr pScreen, int argc, char **argv)
+{
+ vfbScreenInfoPtr pvfb = &vfbScreens[index];
+ int dpix = monitorResolution, dpiy = monitorResolution;
+ int ret;
+ char *pbits;
+
+ if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
+ return FALSE;
+
+ if (dpix == 0)
+ dpix = 100;
+
+ if (dpiy == 0)
+ dpiy = 100;
+
+ pvfb->paddedBytesWidth = PixmapBytePad(pvfb->width, pvfb->depth);
+ pvfb->bitsPerPixel = vfbBitsPerPixel(pvfb->depth);
+ if (pvfb->bitsPerPixel >= 8 )
+ pvfb->paddedWidth = pvfb->paddedBytesWidth / (pvfb->bitsPerPixel / 8);
+ else
+ pvfb->paddedWidth = pvfb->paddedBytesWidth * 8;
+ pbits = vfbAllocateFramebufferMemory(pvfb);
+ if (!pbits) return FALSE;
+
+ switch (pvfb->depth) {
+ case 8:
+ miSetVisualTypesAndMasks (8,
+ ((1 << StaticGray) |
+ (1 << GrayScale) |
+ (1 << StaticColor) |
+ (1 << PseudoColor) |
+ (1 << TrueColor) |
+ (1 << DirectColor)),
+ 8, PseudoColor, 0, 0, 0);
+ break;
+ case 15:
+ miSetVisualTypesAndMasks (15,
+ ((1 << TrueColor) |
+ (1 << DirectColor)),
+ 8, TrueColor, 0x7c00, 0x03e0, 0x001f);
+ break;
+ case 16:
+ miSetVisualTypesAndMasks (16,
+ ((1 << TrueColor) |
+ (1 << DirectColor)),
+ 8, TrueColor, 0xf800, 0x07e0, 0x001f);
+ break;
+ case 24:
+ miSetVisualTypesAndMasks (24,
+ ((1 << TrueColor) |
+ (1 << DirectColor)),
+ 8, TrueColor, 0xff0000, 0x00ff00, 0x0000ff);
+ break;
+ case 30:
+ miSetVisualTypesAndMasks (30,
+ ((1 << TrueColor) |
+ (1 << DirectColor)),
+ 10, TrueColor, 0x3ff00000, 0x000ffc00, 0x000003ff);
+ break;
+ }
+
+ miSetPixmapDepths ();
+
+ ret = fbScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
+ dpix, dpiy, pvfb->paddedWidth,pvfb->bitsPerPixel);
+ if (ret && Render)
+ fbPictureInit (pScreen, 0, 0);
+
+ if (!ret) return FALSE;
+
+ pScreen->InstallColormap = vfbInstallColormap;
+ pScreen->UninstallColormap = vfbUninstallColormap;
+ pScreen->ListInstalledColormaps = vfbListInstalledColormaps;
+
+ pScreen->SaveScreen = vfbSaveScreen;
+ pScreen->StoreColors = vfbStoreColors;
+
+ miDCInitialize(pScreen, &vfbPointerCursorFuncs);
+
+ vfbWriteXWDFileHeader(pScreen);
+
+ pScreen->blackPixel = pvfb->blackPixel;
+ pScreen->whitePixel = pvfb->whitePixel;
+
+ ret = fbCreateDefColormap(pScreen);
+
+ miSetZeroLineBias(pScreen, pvfb->lineBias);
+
+ pvfb->closeScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = vfbCloseScreen;
+
+ return ret;
+
+} /* end vfbScreenInit */
+
+
+void
+InitOutput(ScreenInfo *screenInfo, int argc, char **argv)
+{
+ int i;
+ int NumFormats = 0;
+
+ /* initialize pixmap formats */
+
+ /* must have a pixmap depth to match every screen depth */
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ vfbPixmapDepths[vfbScreens[i].depth] = TRUE;
+ }
+
+ /* RENDER needs a good set of pixmaps. */
+ if (Render) {
+ vfbPixmapDepths[1] = TRUE;
+ vfbPixmapDepths[4] = TRUE;
+ vfbPixmapDepths[8] = TRUE;
+#if 0
+ vfbPixmapDepths[12] = TRUE;
+#endif
+/* vfbPixmapDepths[15] = TRUE; */
+ vfbPixmapDepths[16] = TRUE;
+ vfbPixmapDepths[24] = TRUE;
+#if 0
+ vfbPixmapDepths[30] = TRUE;
+#endif
+ vfbPixmapDepths[32] = TRUE;
+ }
+
+ for (i = 1; i <= 32; i++)
+ {
+ if (vfbPixmapDepths[i])
+ {
+ if (NumFormats >= MAXFORMATS)
+ FatalError ("MAXFORMATS is too small for this server\n");
+ screenInfo->formats[NumFormats].depth = i;
+ screenInfo->formats[NumFormats].bitsPerPixel = vfbBitsPerPixel(i);
+ screenInfo->formats[NumFormats].scanlinePad = BITMAP_SCANLINE_PAD;
+ NumFormats++;
+ }
+ }
+
+ screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+ screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+ screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+ screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+ screenInfo->numPixmapFormats = NumFormats;
+
+ /* initialize screens */
+
+ if (vfbNumScreens < 1)
+ {
+ vfbScreens = &defaultScreenInfo;
+ vfbNumScreens = 1;
+ }
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ if (-1 == AddScreen(vfbScreenInit, argc, argv))
+ {
+ FatalError("Couldn't add screen %d", i);
+ }
+ }
+
+} /* end InitOutput */
diff --git a/xorg-server/hw/xfree86/common/xf86Config.c b/xorg-server/hw/xfree86/common/xf86Config.c
index 4047350c4..19af91509 100644
--- a/xorg-server/hw/xfree86/common/xf86Config.c
+++ b/xorg-server/hw/xfree86/common/xf86Config.c
@@ -1222,6 +1222,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
devs = xnfrealloc(servlayoutp->inputs,
(count + 1) * sizeof(InputInfoPtr));
devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
+ Pointer.fd = -1;
*devs[count - 1] = Pointer;
devs[count - 1]->options =
xf86addNewOption(devs[count -1]->options,
@@ -1267,6 +1268,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
devs = xnfrealloc(servlayoutp->inputs,
(count + 1) * sizeof(InputInfoPtr));
devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
+ Pointer.fd = -1;
*devs[count - 1] = Pointer;
devs[count - 1]->options =
xf86addNewOption(NULL, xnfstrdup("AlwaysCore"), NULL);
@@ -1363,6 +1365,7 @@ checkCoreInputDevices(serverLayoutPtr servlayoutp, Bool implicitLayout)
devs = xnfrealloc(servlayoutp->inputs,
(count + 1) * sizeof(InputInfoPtr));
devs[count - 1] = xnfalloc(sizeof(InputInfoRec));
+ Keyboard.fd = -1;
*devs[count - 1] = Keyboard;
devs[count - 1]->options =
xf86addNewOption(devs[count - 1]->options,
diff --git a/xorg-server/hw/xfree86/common/xf86Configure.c b/xorg-server/hw/xfree86/common/xf86Configure.c
index ba0628ffd..aabb8e11b 100644
--- a/xorg-server/hw/xfree86/common/xf86Configure.c
+++ b/xorg-server/hw/xfree86/common/xf86Configure.c
@@ -749,7 +749,7 @@ DoConfigure(void)
bail:
OsCleanup(TRUE);
- AbortDDX();
+ AbortDDX(EXIT_ERR_CONFIGURE);
fflush(stderr);
exit(0);
}
diff --git a/xorg-server/hw/xfree86/common/xf86Helper.c b/xorg-server/hw/xfree86/common/xf86Helper.c
index da15b0503..a210df042 100644
--- a/xorg-server/hw/xfree86/common/xf86Helper.c
+++ b/xorg-server/hw/xfree86/common/xf86Helper.c
@@ -1198,9 +1198,9 @@ xf86LogInit(void)
}
void
-xf86CloseLog(void)
+xf86CloseLog(enum ExitCode error)
{
- LogClose();
+ LogClose(error);
}
diff --git a/xorg-server/hw/xfree86/common/xf86Init.c b/xorg-server/hw/xfree86/common/xf86Init.c
index 44071996c..94e1a5dbd 100644
--- a/xorg-server/hw/xfree86/common/xf86Init.c
+++ b/xorg-server/hw/xfree86/common/xf86Init.c
@@ -791,6 +791,21 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
NULL);
}
+static InputInfoPtr
+duplicateDevice(InputInfoPtr pInfo)
+{
+ InputInfoPtr dup = calloc(1, sizeof(InputInfoRec));
+ if (dup) {
+ dup->name = strdup(pInfo->name);
+ dup->driver = strdup(pInfo->driver);
+ dup->options = xf86OptionListDuplicate(pInfo->options);
+ /* type_name is a const string */
+ dup->type_name = pInfo->type_name;
+ dup->fd = -1;
+ }
+ return dup;
+}
+
/*
* InitInput --
* Initialize all supported input devices.
@@ -799,7 +814,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv)
void
InitInput(int argc, char **argv)
{
- InputInfoPtr* pDev;
+ InputInfoPtr* pInfo;
DeviceIntPtr dev;
xf86Info.vtRequestsPending = FALSE;
@@ -807,14 +822,21 @@ InitInput(int argc, char **argv)
mieqInit();
/* Initialize all configured input devices */
- for (pDev = xf86ConfigLayout.inputs; pDev && *pDev; pDev++) {
+ for (pInfo = xf86ConfigLayout.inputs; pInfo && *pInfo; pInfo++) {
+ InputInfoPtr dup;
/* Replace obsolete keyboard driver with kbd */
- if (!xf86NameCmp((*pDev)->driver, "keyboard")) {
- strcpy((*pDev)->driver, "kbd");
+ if (!xf86NameCmp((*pInfo)->driver, "keyboard")) {
+ strcpy((*pInfo)->driver, "kbd");
}
+ /* Data passed into xf86NewInputDevice will be freed on shutdown.
+ * Duplicate from xf86ConfigLayout.inputs, otherwise we don't have any
+ * xorg.conf input devices in the second generation
+ */
+ dup = duplicateDevice(*pInfo);
+
/* If one fails, the others will too */
- if (xf86NewInputDevice(*pDev, &dev, TRUE) == BadAlloc)
+ if (xf86NewInputDevice(dup, &dev, TRUE) == BadAlloc)
break;
}
@@ -880,7 +902,7 @@ OsVendorInit(void)
*/
void
-ddxGiveUp(void)
+ddxGiveUp(enum ExitCode error)
{
int i;
@@ -907,7 +929,7 @@ ddxGiveUp(void)
if (xorgHWOpenConsole)
xf86CloseConsole();
- xf86CloseLog();
+ xf86CloseLog(error);
/* If an unexpected signal was caught, dump a core for debugging */
if (xf86Info.caughtSignal)
@@ -924,7 +946,7 @@ ddxGiveUp(void)
*/
void
-AbortDDX(void)
+AbortDDX(enum ExitCode error)
{
int i;
@@ -957,7 +979,7 @@ AbortDDX(void)
* This is needed for an abnormal server exit, since the normal exit stuff
* MUST also be performed (i.e. the vt must be left in a defined state)
*/
- ddxGiveUp();
+ ddxGiveUp(error);
}
void
diff --git a/xorg-server/hw/xfree86/common/xf86Option.c b/xorg-server/hw/xfree86/common/xf86Option.c
index 08f143347..576796d6c 100644
--- a/xorg-server/hw/xfree86/common/xf86Option.c
+++ b/xorg-server/hw/xfree86/common/xf86Option.c
@@ -340,7 +340,7 @@ pointer
xf86AddNewOption(pointer head, const char *name, const char *val)
{
/* XXX These should actually be allocated in the parser library. */
- char *tmp = strdup(val);
+ char *tmp = val ? strdup(val) : NULL;
char *tmp_name = strdup(name);
return xf86addNewOption(head, tmp_name, tmp);
diff --git a/xorg-server/hw/xfree86/common/xf86Priv.h b/xorg-server/hw/xfree86/common/xf86Priv.h
index a77d38fd3..436594ba6 100644
--- a/xorg-server/hw/xfree86/common/xf86Priv.h
+++ b/xorg-server/hw/xfree86/common/xf86Priv.h
@@ -140,7 +140,7 @@ extern _X_EXPORT pmWait (*xf86PMConfirmEventToOs)(int fd,pmEvent event);
/* xf86Helper.c */
extern _X_EXPORT void xf86LogInit(void);
-extern _X_EXPORT void xf86CloseLog(void);
+extern _X_EXPORT void xf86CloseLog(enum ExitCode error);
/* xf86Init.c */
extern _X_EXPORT Bool xf86LoadModules(char **list, pointer *optlist);
diff --git a/xorg-server/hw/xfree86/common/xf86ShowOpts.c b/xorg-server/hw/xfree86/common/xf86ShowOpts.c
index 7aa79eb6a..a8059168d 100644
--- a/xorg-server/hw/xfree86/common/xf86ShowOpts.c
+++ b/xorg-server/hw/xfree86/common/xf86ShowOpts.c
@@ -1,130 +1,130 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86ShopwOpts.c,v 3.80 2003/10/08 14:58:27 dawes Exp $ */
-/*
- * Copyright 2000-2002 by Alan Hourihane, Flint Mountain, North Wales.
- *
- * 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.
- *
- * Author: Marcus Schaefer, ms@suse.de
- *
- */
-
-#include <ctype.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <X11/X.h>
-#include <X11/Xmd.h>
-#include "os.h"
-#ifdef XFree86LOADER
-#include "loaderProcs.h"
-#endif
-#include "xf86.h"
-#include "xf86Config.h"
-#include "xf86_OSlib.h"
-#include "xf86Priv.h"
-/* #include "xf86PciData.h" */
-#define IN_XSERVER
-#include "xf86Parser.h"
-#include "xf86tokens.h"
-#include "Configint.h"
-#include "xf86DDC.h"
-#if defined(__sparc__) && !defined(__OpenBSD__)
-#include "xf86Bus.h"
-#include "xf86Sbus.h"
-#endif
-#include "globals.h"
-
-static const char*
-optionTypeToSting(OptionValueType type)
-{
- switch (type) {
- case OPTV_NONE:
- return "";
- case OPTV_INTEGER:
- return "<int>";
- case OPTV_STRING:
- return "<str>";
- case OPTV_ANYSTR:
- return "<str>";
- case OPTV_REAL:
- return "<real>";
- case OPTV_BOOLEAN:
- return "<bool>";
- case OPTV_FREQ:
- return "<freq>";
- case OPTV_PERCENT:
- return "<percent>";
- default:
- return "<undef>";
- }
-}
-
-void DoShowOptions (void) {
- int i = 0;
- char **vlist = 0;
- char *pSymbol = 0;
- XF86ModuleData *initData = 0;
- if (! (vlist = xf86DriverlistFromCompile())) {
- ErrorF("Missing output drivers\n");
- goto bail;
- }
- xf86LoadModules (vlist,0);
- free(vlist);
- for (i = 0; i < xf86NumDrivers; i++) {
- if (xf86DriverList[i]->AvailableOptions) {
- OptionInfoPtr pOption = (OptionInfoPtr)(*xf86DriverList[i]->AvailableOptions)(0,0);
- if (! pOption) {
- ErrorF ("(EE) Couldn't read option table for %s driver\n",
- xf86DriverList[i]->driverName
- );
- continue;
- }
- XNFasprintf(&pSymbol, "%sModuleData",
- xf86DriverList[i]->driverName);
- initData = LoaderSymbol (pSymbol);
- if (initData) {
- XF86ModuleVersionInfo *vers = initData->vers;
- OptionInfoPtr p;
- ErrorF ("Driver[%d]:%s[%s] {\n",
- i,xf86DriverList[i]->driverName,vers->vendor
- );
- for (p = pOption; p->name != NULL; p++) {
- const char *opttype = optionTypeToSting(p->type);
- /* XXX: Why overallocate by 2 bytes?
- * Otherwise, this would be strdup()
- */
- char *optname = malloc(strlen(p->name) + 2 + 1);
- if (!optname) {
- continue;
- }
- sprintf(optname, "%s", p->name);
- ErrorF ("\t%s:%s\n", optname,opttype);
- }
- ErrorF ("}\n");
- }
- }
- }
- bail:
- OsCleanup (TRUE);
- AbortDDX ();
- fflush (stderr);
- exit (0);
-}
+/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86ShopwOpts.c,v 3.80 2003/10/08 14:58:27 dawes Exp $ */
+/*
+ * Copyright 2000-2002 by Alan Hourihane, Flint Mountain, North Wales.
+ *
+ * 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.
+ *
+ * Author: Marcus Schaefer, ms@suse.de
+ *
+ */
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <X11/X.h>
+#include <X11/Xmd.h>
+#include "os.h"
+#ifdef XFree86LOADER
+#include "loaderProcs.h"
+#endif
+#include "xf86.h"
+#include "xf86Config.h"
+#include "xf86_OSlib.h"
+#include "xf86Priv.h"
+/* #include "xf86PciData.h" */
+#define IN_XSERVER
+#include "xf86Parser.h"
+#include "xf86tokens.h"
+#include "Configint.h"
+#include "xf86DDC.h"
+#if defined(__sparc__) && !defined(__OpenBSD__)
+#include "xf86Bus.h"
+#include "xf86Sbus.h"
+#endif
+#include "globals.h"
+
+static const char*
+optionTypeToSting(OptionValueType type)
+{
+ switch (type) {
+ case OPTV_NONE:
+ return "";
+ case OPTV_INTEGER:
+ return "<int>";
+ case OPTV_STRING:
+ return "<str>";
+ case OPTV_ANYSTR:
+ return "<str>";
+ case OPTV_REAL:
+ return "<real>";
+ case OPTV_BOOLEAN:
+ return "<bool>";
+ case OPTV_FREQ:
+ return "<freq>";
+ case OPTV_PERCENT:
+ return "<percent>";
+ default:
+ return "<undef>";
+ }
+}
+
+void DoShowOptions (void) {
+ int i = 0;
+ char **vlist = 0;
+ char *pSymbol = 0;
+ XF86ModuleData *initData = 0;
+ if (! (vlist = xf86DriverlistFromCompile())) {
+ ErrorF("Missing output drivers\n");
+ goto bail;
+ }
+ xf86LoadModules (vlist,0);
+ free(vlist);
+ for (i = 0; i < xf86NumDrivers; i++) {
+ if (xf86DriverList[i]->AvailableOptions) {
+ OptionInfoPtr pOption = (OptionInfoPtr)(*xf86DriverList[i]->AvailableOptions)(0,0);
+ if (! pOption) {
+ ErrorF ("(EE) Couldn't read option table for %s driver\n",
+ xf86DriverList[i]->driverName
+ );
+ continue;
+ }
+ XNFasprintf(&pSymbol, "%sModuleData",
+ xf86DriverList[i]->driverName);
+ initData = LoaderSymbol (pSymbol);
+ if (initData) {
+ XF86ModuleVersionInfo *vers = initData->vers;
+ OptionInfoPtr p;
+ ErrorF ("Driver[%d]:%s[%s] {\n",
+ i,xf86DriverList[i]->driverName,vers->vendor
+ );
+ for (p = pOption; p->name != NULL; p++) {
+ const char *opttype = optionTypeToSting(p->type);
+ /* XXX: Why overallocate by 2 bytes?
+ * Otherwise, this would be strdup()
+ */
+ char *optname = malloc(strlen(p->name) + 2 + 1);
+ if (!optname) {
+ continue;
+ }
+ sprintf(optname, "%s", p->name);
+ ErrorF ("\t%s:%s\n", optname,opttype);
+ }
+ ErrorF ("}\n");
+ }
+ }
+ }
+ bail:
+ OsCleanup (TRUE);
+ AbortDDX (EXIT_ERR_DRIVERS);
+ fflush (stderr);
+ exit (0);
+}
diff --git a/xorg-server/hw/xfree86/common/xf86Xinput.c b/xorg-server/hw/xfree86/common/xf86Xinput.c
index afef0994d..a53531cc1 100644
--- a/xorg-server/hw/xfree86/common/xf86Xinput.c
+++ b/xorg-server/hw/xfree86/common/xf86Xinput.c
@@ -844,6 +844,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
{
OsReleaseSignals();
xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", pInfo->name);
+ RemoveDevice(dev, TRUE);
rval = BadMatch;
goto unwind;
}
diff --git a/xorg-server/hw/xnest/Init.c b/xorg-server/hw/xnest/Init.c
index 5f330c970..263565977 100644
--- a/xorg-server/hw/xnest/Init.c
+++ b/xorg-server/hw/xnest/Init.c
@@ -114,16 +114,16 @@ CloseInput(void)
/*
* DDX - specific abort routine. Called by AbortServer().
*/
-void AbortDDX(void)
+void AbortDDX(enum ExitCode error)
{
xnestDoFullGeneration = True;
xnestCloseDisplay();
}
/* Called by GiveUp(). */
-void ddxGiveUp(void)
+void ddxGiveUp(enum ExitCode error)
{
- AbortDDX();
+ AbortDDX(error);
}
#ifdef __APPLE__
diff --git a/xorg-server/hw/xquartz/darwin.c b/xorg-server/hw/xquartz/darwin.c
index 0b2f12fa7..8250f064a 100644
--- a/xorg-server/hw/xquartz/darwin.c
+++ b/xorg-server/hw/xquartz/darwin.c
@@ -766,9 +766,9 @@ void ddxUseMsg( void )
* ddxGiveUp --
* Device dependent cleanup. Called by dix before normal server death.
*/
-void ddxGiveUp( void )
+void ddxGiveUp( enum ExitCode error )
{
- ErrorF( "Quitting Xquartz\n" );
+ LogClose(error);
}
@@ -779,7 +779,7 @@ void ddxGiveUp( void )
* are closed.
*/
_X_NORETURN
-void AbortDDX( void ) {
+void AbortDDX( enum ExitCode error ) {
ErrorF( " AbortDDX\n" );
OsAbort();
}
diff --git a/xorg-server/hw/xwin/InitOutput.c b/xorg-server/hw/xwin/InitOutput.c
index ae56c51fa..f79132c42 100644
--- a/xorg-server/hw/xwin/InitOutput.c
+++ b/xorg-server/hw/xwin/InitOutput.c
@@ -177,7 +177,7 @@ ddxBeforeReset (void)
/* See Porting Layer Definition - p. 57 */
void
-ddxGiveUp (void)
+ddxGiveUp (enum ExitCode error)
{
int i;
@@ -212,7 +212,7 @@ ddxGiveUp (void)
g_pszLogFile = LogInit (g_pszLogFile, NULL);
g_fLogInited = TRUE;
}
- LogClose ();
+ LogClose (error);
/*
* At this point we aren't creating any new screens, so
@@ -242,10 +242,10 @@ ddxGiveUp (void)
/* See Porting Layer Definition - p. 57 */
void
-AbortDDX (void)
+AbortDDX (enum ExitCode error)
{
winDebug ("AbortDDX\n");
- ddxGiveUp ();
+ ddxGiveUp (error);
}
#ifdef __CYGWIN__
@@ -906,7 +906,7 @@ ddxUseMsg(void)
g_pszLogFile = LogInit (g_pszLogFile, NULL);
g_fLogInited = TRUE;
}
- LogClose ();
+ LogClose (EXIT_NO_ERROR);
/* Notify user where UseMsg text can be found.*/
if (!g_fNoHelpMessageBox)
diff --git a/xorg-server/hw/xwin/Makefile.am b/xorg-server/hw/xwin/Makefile.am
index 0afd81883..70f6cf7a6 100644
--- a/xorg-server/hw/xwin/Makefile.am
+++ b/xorg-server/hw/xwin/Makefile.am
@@ -176,27 +176,7 @@ install-exec-hook:
EXTRA_DIST = \
$(xwinconfig_DATA) \
X.ico \
- XWin.rc \
- xlaunch/config.cc \
- xlaunch/COPYING \
- xlaunch/main.cc \
- xlaunch/resources/dialog.rc \
- xlaunch/resources/fullscreen.bmp \
- xlaunch/resources/images.rc \
- xlaunch/resources/multiwindow.bmp \
- xlaunch/resources/nodecoration.bmp \
- xlaunch/resources/resources.h \
- xlaunch/resources/resources.rc \
- xlaunch/resources/strings.rc \
- xlaunch/resources/windowed.bmp \
- xlaunch/window/dialog.cc \
- xlaunch/window/dialog.h \
- xlaunch/window/util.cc \
- xlaunch/window/util.h \
- xlaunch/window/window.cc \
- xlaunch/window/window.h \
- xlaunch/window/wizard.cc \
- xlaunch/window/wizard.h
+ XWin.rc
relink:
$(AM_V_at)rm -f XWin$(EXEEXT) && $(MAKE) XWin$(EXEEXT)
diff --git a/xorg-server/hw/xwin/winerror.c b/xorg-server/hw/xwin/winerror.c
index 47e1bd86f..e95be3f4c 100644
--- a/xorg-server/hw/xwin/winerror.c
+++ b/xorg-server/hw/xwin/winerror.c
@@ -1,167 +1,167 @@
-/*
- *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors: Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-
-#include <../xfree86/common/xorgVersion.h>
-#include "win.h"
-
-extern Bool g_fSilentDupError;
-#ifdef DDXOSVERRORF
-/* Prototype */
-void
-OsVendorVErrorF (const char *pszFormat, va_list va_args);
-
-void
-OsVendorVErrorF (const char *pszFormat, va_list va_args)
-{
-#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
- /* make sure the clipboard and multiwindow threads do not interfere the
- * main thread */
- static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER;
-
- /* Lock the printing mutex */
- pthread_mutex_lock (&s_pmPrinting);
-#endif
-
- /*
- If we want to silence it,
- detect if we are going to abort due to duplication error
- */
- if (g_fSilentDupError)
- {
- if ((strcmp(pszFormat,
- "InitOutput - Duplicate invocation on display "
- "number: %s. Exiting.\n") == 0)
- || (strcmp(pszFormat,
- "Server is already active for display %s\n%s %s\n%s\n") == 0)
- || (strcmp(pszFormat,
- "MakeAllCOTSServerListeners: server already running\n") == 0))
- {
- g_fSilentFatalError = TRUE;
- }
- }
-
- /* Print the error message to a log file, could be stderr */
- LogVWrite (0, pszFormat, va_args);
-
-#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
- /* Unlock the printing mutex */
- pthread_mutex_unlock (&s_pmPrinting);
-#endif
-}
-#endif
-
-
-/*
- * os/util.c/FatalError () calls our vendor ErrorF, so the message
- * from a FatalError will be logged. Thus, the message for the
- * fatal error is not passed to this function.
- *
- * Attempt to do last-ditch, safe, important cleanup here.
- */
-char g_FatalErrorMessage[1024];
-void
-OsVendorFatalError (void)
-{
- /* Don't give duplicate warning if UseMsg was called */
- if (g_fSilentFatalError)
- return;
-
- if (!g_fLogInited) {
- g_fLogInited = TRUE;
- g_pszLogFile = LogInit (g_pszLogFile, NULL);
- }
- LogClose ();
-
- winMessageBoxF (
- "A fatal error has occurred and " PROJECT_NAME " will now exit.\n" \
- "%s\n"
- "Please open %s for more information.\n",
- MB_ICONERROR, g_FatalErrorMessage, (g_pszLogFile?g_pszLogFile:"the logfile"));
-}
-
-
-/*
- * winMessageBoxF - Print a formatted error message in a useful
- * message box.
- */
-
-void
-winMessageBoxF (const char *pszError, UINT uType, ...)
-{
- char * pszErrorF = NULL;
- char * pszMsgBox = NULL;
- va_list args;
- int size;
-
- va_start(args, uType);
- size = vasprintf (&pszErrorF, pszError, args);
- va_end(args);
- if (size == -1) {
- pszErrorF = NULL;
- goto winMessageBoxF_Cleanup;
- }
-
-#define MESSAGEBOXF \
- "%s\n" \
- "Vendor: %s\n" \
- "Release: %d.%d.%d.%d\n" \
- "Contact: %s\n" \
- "%s\n\n" \
- "XWin was started with the following command-line:\n\n" \
- "%s\n"
-
- size = asprintf (&pszMsgBox, MESSAGEBOXF,
- pszErrorF, XVENDORNAME,
- XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH,
- XORG_VERSION_SNAP,
- BUILDERADDR,
- BUILDERSTRING,
- g_pszCommandLine);
-
- if (size == -1) {
- pszMsgBox = NULL;
- goto winMessageBoxF_Cleanup;
- }
-
- /* Display the message box string */
- MessageBox (NULL,
- pszMsgBox,
- PROJECT_NAME,
- MB_OK | uType);
-
- winMessageBoxF_Cleanup:
- free(pszErrorF);
- free(pszMsgBox);
-#undef MESSAGEBOXF
-}
+/*
+ *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors: Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include <../xfree86/common/xorgVersion.h>
+#include "win.h"
+
+extern Bool g_fSilentDupError;
+#ifdef DDXOSVERRORF
+/* Prototype */
+void
+OsVendorVErrorF (const char *pszFormat, va_list va_args);
+
+void
+OsVendorVErrorF (const char *pszFormat, va_list va_args)
+{
+#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
+ /* make sure the clipboard and multiwindow threads do not interfere the
+ * main thread */
+ static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER;
+
+ /* Lock the printing mutex */
+ pthread_mutex_lock (&s_pmPrinting);
+#endif
+
+ /*
+ If we want to silence it,
+ detect if we are going to abort due to duplication error
+ */
+ if (g_fSilentDupError)
+ {
+ if ((strcmp(pszFormat,
+ "InitOutput - Duplicate invocation on display "
+ "number: %s. Exiting.\n") == 0)
+ || (strcmp(pszFormat,
+ "Server is already active for display %s\n%s %s\n%s\n") == 0)
+ || (strcmp(pszFormat,
+ "MakeAllCOTSServerListeners: server already running\n") == 0))
+ {
+ g_fSilentFatalError = TRUE;
+ }
+ }
+
+ /* Print the error message to a log file, could be stderr */
+ LogVWrite (0, pszFormat, va_args);
+
+#if defined(XWIN_CLIPBOARD) || defined (XWIN_MULTIWINDOW)
+ /* Unlock the printing mutex */
+ pthread_mutex_unlock (&s_pmPrinting);
+#endif
+}
+#endif
+
+
+/*
+ * os/util.c/FatalError () calls our vendor ErrorF, so the message
+ * from a FatalError will be logged. Thus, the message for the
+ * fatal error is not passed to this function.
+ *
+ * Attempt to do last-ditch, safe, important cleanup here.
+ */
+char g_FatalErrorMessage[1024];
+void
+OsVendorFatalError (void)
+{
+ /* Don't give duplicate warning if UseMsg was called */
+ if (g_fSilentFatalError)
+ return;
+
+ if (!g_fLogInited) {
+ g_fLogInited = TRUE;
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ }
+ LogClose (EXIT_ERR_ABORT);
+
+ winMessageBoxF (
+ "A fatal error has occurred and " PROJECT_NAME " will now exit.\n" \
+ "%s\n"
+ "Please open %s for more information.\n",
+ MB_ICONERROR, g_FatalErrorMessage, (g_pszLogFile?g_pszLogFile:"the logfile"));
+}
+
+
+/*
+ * winMessageBoxF - Print a formatted error message in a useful
+ * message box.
+ */
+
+void
+winMessageBoxF (const char *pszError, UINT uType, ...)
+{
+ char * pszErrorF = NULL;
+ char * pszMsgBox = NULL;
+ va_list args;
+ int size;
+
+ va_start(args, uType);
+ size = vasprintf (&pszErrorF, pszError, args);
+ va_end(args);
+ if (size == -1) {
+ pszErrorF = NULL;
+ goto winMessageBoxF_Cleanup;
+ }
+
+#define MESSAGEBOXF \
+ "%s\n" \
+ "Vendor: %s\n" \
+ "Release: %d.%d.%d.%d\n" \
+ "Contact: %s\n" \
+ "%s\n\n" \
+ "XWin was started with the following command-line:\n\n" \
+ "%s\n"
+
+ size = asprintf (&pszMsgBox, MESSAGEBOXF,
+ pszErrorF, XVENDORNAME,
+ XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH,
+ XORG_VERSION_SNAP,
+ BUILDERADDR,
+ BUILDERSTRING,
+ g_pszCommandLine);
+
+ if (size == -1) {
+ pszMsgBox = NULL;
+ goto winMessageBoxF_Cleanup;
+ }
+
+ /* Display the message box string */
+ MessageBox (NULL,
+ pszMsgBox,
+ PROJECT_NAME,
+ MB_OK | uType);
+
+ winMessageBoxF_Cleanup:
+ free(pszErrorF);
+ free(pszMsgBox);
+#undef MESSAGEBOXF
+}