summaryrefslogtreecommitdiff
path: root/hw/vfb
diff options
context:
space:
mode:
authorKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:54 +0000
committerKaleb Keithley <kaleb@freedesktop.org>2003-11-14 15:54:54 +0000
commitded6147bfb5d75ff1e67c858040a628b61bc17d1 (patch)
tree82355105e93cdac89ef7d987424351c77545faf0 /hw/vfb
parentcb6ef07bf01e72d1a6e6e83ceb7f76d6534da941 (diff)
R6.6 is the Xorg base-lineXORG-MAIN
Diffstat (limited to 'hw/vfb')
-rw-r--r--hw/vfb/InitInput.c357
-rw-r--r--hw/vfb/InitOutput.c981
-rw-r--r--hw/vfb/Xvfb.man.pre128
-rw-r--r--hw/vfb/lk201kbd.h159
4 files changed, 1625 insertions, 0 deletions
diff --git a/hw/vfb/InitInput.c b/hw/vfb/InitInput.c
new file mode 100644
index 000000000..255c56f8e
--- /dev/null
+++ b/hw/vfb/InitInput.c
@@ -0,0 +1,357 @@
+/* $Xorg: InitInput.c,v 1.4 2001/02/09 02:04:44 xorgcvs Exp $ */
+/*
+
+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.
+
+*/
+
+#include "X11/X.h"
+#define NEED_EVENTS
+#include "X11/Xproto.h"
+#include "scrnintstr.h"
+#include "inputstr.h"
+#include "X11/Xos.h"
+#include "mibstore.h"
+#include "mipointer.h"
+#include "lk201kbd.h"
+#include "keysym.h"
+
+Bool
+LegalModifier(key, pDev)
+ unsigned int key;
+ DevicePtr pDev;
+{
+ return TRUE;
+}
+
+void
+ProcessInputEvents()
+{
+ mieqProcessInputEvents();
+ miPointerUpdate();
+}
+
+#define VFB_MIN_KEY 8
+#define VFB_MAX_KEY 255
+KeySym map[MAP_LENGTH * LK201_GLYPHS_PER_KEY];
+
+/* The only reason for using the LK201 mappings here was that they were
+ * easy to lift.
+ */
+static Bool
+GetLK201Mappings(pKeySyms, pModMap)
+ KeySymsPtr pKeySyms;
+ CARD8 *pModMap;
+{
+#define INDEX(in) ((in - VFB_MIN_KEY) * LK201_GLYPHS_PER_KEY)
+ int i;
+
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+ pModMap[ KEY_LOCK ] = LockMask;
+ pModMap[ KEY_SHIFT ] = ShiftMask;
+ pModMap[ KEY_CTRL ] = ControlMask;
+ pModMap[ KEY_COMPOSE ] = Mod1Mask;
+
+ pKeySyms->minKeyCode = VFB_MIN_KEY;
+ pKeySyms->maxKeyCode = VFB_MAX_KEY;
+ pKeySyms->mapWidth = LK201_GLYPHS_PER_KEY;
+ pKeySyms->map = map;
+
+ for (i = 0; i < (MAP_LENGTH * LK201_GLYPHS_PER_KEY); i++)
+ map[i] = NoSymbol; /* make sure it is restored */
+
+ map[INDEX(KEY_F1)] = XK_F1;
+ map[INDEX(KEY_F2)] = XK_F2;
+ map[INDEX(KEY_F3)] = XK_F3;
+ map[INDEX(KEY_F4)] = XK_F4;
+ map[INDEX(KEY_F5)] = XK_F5;
+ map[INDEX(KEY_F6)] = XK_F6;
+ map[INDEX(KEY_F7)] = XK_F7;
+ map[INDEX(KEY_F8)] = XK_F8;
+ map[INDEX(KEY_F9)] = XK_F9;
+ map[INDEX(KEY_F10)] = XK_F10;
+ map[INDEX(KEY_F11)] = XK_F11;
+ map[INDEX(KEY_F12)] = XK_F12;
+ map[INDEX(KEY_F13)] = XK_F13;
+ map[INDEX(KEY_F14)] = XK_F14;
+
+ map[INDEX(KEY_HELP)] = XK_Help;
+ map[INDEX(KEY_MENU)] = XK_Menu;
+
+ map[INDEX(KEY_F17)] = XK_F17;
+ map[INDEX(KEY_F18)] = XK_F18;
+ map[INDEX(KEY_F19)] = XK_F19;
+ map[INDEX(KEY_F20)] = XK_F20;
+
+ map[INDEX(KEY_FIND)] = XK_Find;
+ map[INDEX(KEY_INSERT_HERE)] = XK_Insert;
+ map[INDEX(KEY_REMOVE)] = XK_Delete;
+ map[INDEX(KEY_SELECT)] = XK_Select;
+ map[INDEX(KEY_PREV_SCREEN)] = XK_Prior;
+ map[INDEX(KEY_NEXT_SCREEN)] = XK_Next;
+
+ map[INDEX(KEY_KP_0)] = XK_KP_0;
+ map[INDEX(KEY_KP_PERIOD)] = XK_KP_Decimal;
+ map[INDEX(KEY_KP_ENTER)] = XK_KP_Enter;
+ map[INDEX(KEY_KP_1)] = XK_KP_1;
+ map[INDEX(KEY_KP_2)] = XK_KP_2;
+ map[INDEX(KEY_KP_3)] = XK_KP_3;
+ map[INDEX(KEY_KP_4)] = XK_KP_4;
+ map[INDEX(KEY_KP_5)] = XK_KP_5;
+ map[INDEX(KEY_KP_6)] = XK_KP_6;
+ map[INDEX(KEY_KP_COMMA)] = XK_KP_Separator;
+ map[INDEX(KEY_KP_7)] = XK_KP_7;
+ map[INDEX(KEY_KP_8)] = XK_KP_8;
+ map[INDEX(KEY_KP_9)] = XK_KP_9;
+ map[INDEX(KEY_KP_HYPHEN)] = XK_KP_Subtract;
+ map[INDEX(KEY_KP_PF1)] = XK_KP_F1;
+ map[INDEX(KEY_KP_PF2)] = XK_KP_F2;
+ map[INDEX(KEY_KP_PF3)] = XK_KP_F3;
+ map[INDEX(KEY_KP_PF4)] = XK_KP_F4;
+
+ map[INDEX(KEY_LEFT)] = XK_Left;
+ map[INDEX(KEY_RIGHT)] = XK_Right;
+ map[INDEX(KEY_DOWN)] = XK_Down;
+ map[INDEX(KEY_UP)] = XK_Up;
+
+ map[INDEX(KEY_SHIFT)] = XK_Shift_L;
+ map[INDEX(KEY_CTRL)] = XK_Control_L;
+ map[INDEX(KEY_LOCK)] = XK_Caps_Lock;
+ map[INDEX(KEY_COMPOSE)] = XK_Multi_key;
+ map[INDEX(KEY_COMPOSE)+1] = XK_Meta_L;
+ map[INDEX(KEY_DELETE)] = XK_Delete;
+ map[INDEX(KEY_RETURN)] = XK_Return;
+ map[INDEX(KEY_TAB)] = XK_Tab;
+
+ map[INDEX(KEY_TILDE)] = XK_quoteleft;
+ map[INDEX(KEY_TILDE)+1] = XK_asciitilde;
+
+ map[INDEX(KEY_TR_1)] = XK_1;
+ map[INDEX(KEY_TR_1)+1] = XK_exclam;
+ map[INDEX(KEY_Q)] = XK_Q;
+ map[INDEX(KEY_A)] = XK_A;
+ map[INDEX(KEY_Z)] = XK_Z;
+
+ map[INDEX(KEY_TR_2)] = XK_2;
+ map[INDEX(KEY_TR_2)+1] = XK_at;
+
+ map[INDEX(KEY_W)] = XK_W;
+ map[INDEX(KEY_S)] = XK_S;
+ map[INDEX(KEY_X)] = XK_X;
+
+ map[INDEX(KEY_LANGLE_RANGLE)] = XK_less;
+ map[INDEX(KEY_LANGLE_RANGLE)+1] = XK_greater;
+
+ map[INDEX(KEY_TR_3)] = XK_3;
+ map[INDEX(KEY_TR_3)+1] = XK_numbersign;
+
+ map[INDEX(KEY_E)] = XK_E;
+ map[INDEX(KEY_D)] = XK_D;
+ map[INDEX(KEY_C)] = XK_C;
+
+ map[INDEX(KEY_TR_4)] = XK_4;
+ map[INDEX(KEY_TR_4)+1] = XK_dollar;
+
+ map[INDEX(KEY_R)] = XK_R;
+ map[INDEX(KEY_F)] = XK_F;
+ map[INDEX(KEY_V)] = XK_V;
+ map[INDEX(KEY_SPACE)] = XK_space;
+
+ map[INDEX(KEY_TR_5)] = XK_5;
+ map[INDEX(KEY_TR_5)+1] = XK_percent;
+
+ map[INDEX(KEY_T)] = XK_T;
+ map[INDEX(KEY_G)] = XK_G;
+ map[INDEX(KEY_B)] = XK_B;
+
+ map[INDEX(KEY_TR_6)] = XK_6;
+ map[INDEX(KEY_TR_6)+1] = XK_asciicircum;
+
+ map[INDEX(KEY_Y)] = XK_Y;
+ map[INDEX(KEY_H)] = XK_H;
+ map[INDEX(KEY_N)] = XK_N;
+
+ map[INDEX(KEY_TR_7)] = XK_7;
+ map[INDEX(KEY_TR_7)+1] = XK_ampersand;
+
+ map[INDEX(KEY_U)] = XK_U;
+ map[INDEX(KEY_J)] = XK_J;
+ map[INDEX(KEY_M)] = XK_M;
+
+ map[INDEX(KEY_TR_8)] = XK_8;
+ map[INDEX(KEY_TR_8)+1] = XK_asterisk;
+
+ map[INDEX(KEY_I)] = XK_I;
+ map[INDEX(KEY_K)] = XK_K;
+
+ map[INDEX(KEY_COMMA)] = XK_comma;
+ map[INDEX(KEY_COMMA)+1] = XK_less;
+
+ map[INDEX(KEY_TR_9)] = XK_9;
+ map[INDEX(KEY_TR_9)+1] = XK_parenleft;
+
+ map[INDEX(KEY_O)] = XK_O;
+ map[INDEX(KEY_L)] = XK_L;
+
+ map[INDEX(KEY_PERIOD)] = XK_period;
+ map[INDEX(KEY_PERIOD)+1] = XK_greater;
+
+ map[INDEX(KEY_TR_0)] = XK_0;
+ map[INDEX(KEY_TR_0)+1] = XK_parenright;
+
+ map[INDEX(KEY_P)] = XK_P;
+
+ map[INDEX(KEY_SEMICOLON)] = XK_semicolon;
+ map[INDEX(KEY_SEMICOLON)+1] = XK_colon;
+
+ map[INDEX(KEY_QMARK)] = XK_slash;
+ map[INDEX(KEY_QMARK)+1] = XK_question;
+
+ map[INDEX(KEY_PLUS)] = XK_equal;
+ map[INDEX(KEY_PLUS)+1] = XK_plus;
+
+ map[INDEX(KEY_RBRACE)] = XK_bracketright;
+ map[INDEX(KEY_RBRACE)+1] = XK_braceright;
+
+ map[INDEX(KEY_VBAR)] = XK_backslash;
+ map[INDEX(KEY_VBAR)+1] = XK_bar;
+
+ map[INDEX(KEY_UBAR)] = XK_minus;
+ map[INDEX(KEY_UBAR)+1] = XK_underscore;
+
+ map[INDEX(KEY_LBRACE)] = XK_bracketleft;
+ map[INDEX(KEY_LBRACE)+1] = XK_braceleft;
+
+ map[INDEX(KEY_QUOTE)] = XK_quoteright;
+ map[INDEX(KEY_QUOTE)+1] = XK_quotedbl;
+
+ map[INDEX(KEY_F11)] = XK_Escape;
+
+ return TRUE;
+#undef INDEX
+}
+
+static int
+vfbKeybdProc(pDevice, onoff)
+ DeviceIntPtr pDevice;
+ int onoff;
+{
+ KeySymsRec keySyms;
+ CARD8 modMap[MAP_LENGTH];
+ int i;
+ DevicePtr pDev = (DevicePtr)pDevice;
+
+ switch (onoff)
+ {
+ case DEVICE_INIT:
+ GetLK201Mappings(&keySyms, modMap);
+ InitKeyboardDeviceStruct(pDev, &keySyms, modMap,
+ (BellProcPtr)NoopDDA, (KbdCtrlProcPtr)NoopDDA);
+ break;
+ case DEVICE_ON:
+ pDev->on = TRUE;
+ break;
+ case DEVICE_OFF:
+ pDev->on = FALSE;
+ break;
+ case DEVICE_CLOSE:
+ break;
+ }
+ return Success;
+}
+
+static int
+vfbMouseProc(pDevice, onoff)
+ DeviceIntPtr pDevice;
+ int onoff;
+{
+ BYTE map[4];
+ DevicePtr pDev = (DevicePtr)pDevice;
+
+ switch (onoff)
+ {
+ case DEVICE_INIT:
+ map[1] = 1;
+ map[2] = 2;
+ map[3] = 3;
+ InitPointerDeviceStruct(pDev, map, 3, miPointerGetMotionEvents,
+ (PtrCtrlProcPtr)NoopDDA, miPointerGetMotionBufferSize());
+ break;
+
+ case DEVICE_ON:
+ pDev->on = TRUE;
+ break;
+
+ case DEVICE_OFF:
+ pDev->on = FALSE;
+ break;
+
+ case DEVICE_CLOSE:
+ break;
+ }
+ return Success;
+}
+
+void
+InitInput(argc, argv)
+ int argc;
+ char *argv[];
+{
+ DevicePtr p, k;
+ p = AddInputDevice(vfbMouseProc, TRUE);
+ k = AddInputDevice(vfbKeybdProc, TRUE);
+ RegisterPointerDevice(p);
+ RegisterKeyboardDevice(k);
+ miRegisterPointerDevice(screenInfo.screens[0], p);
+ (void)mieqInit (k, p);
+}
+
+#ifdef XTESTEXT1
+void
+XTestGenerateEvent(dev_type, keycode, keystate, mousex, mousey)
+ int dev_type;
+ int keycode;
+ int keystate;
+ int mousex;
+ int mousey;
+{
+}
+
+void
+XTestGetPointerPos(fmousex, fmousey)
+ short *fmousex, *fmousey;
+{
+}
+
+void
+XTestJumpPointer(jx, jy, dev_type)
+ int jx;
+ int jy;
+ int dev_type;
+{
+}
+#endif
+
diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
new file mode 100644
index 000000000..c2334e745
--- /dev/null
+++ b/hw/vfb/InitOutput.c
@@ -0,0 +1,981 @@
+/* $Xorg: InitOutput.c,v 1.4 2001/02/09 02:04:45 xorgcvs Exp $ */
+/*
+
+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 WIN32
+#include <X11/Xwinsock.h>
+#endif
+#include <stdio.h>
+#include "X11/X.h"
+#define NEED_EVENTS
+#include "X11/Xproto.h"
+#include "X11/Xos.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#define PSZ 8
+#include "cfb.h"
+#include "mibstore.h"
+#include "colormapst.h"
+#include "gcstruct.h"
+#include "input.h"
+#include "mipointer.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"
+
+extern char *display;
+
+#define VFB_DEFAULT_WIDTH 1280
+#define VFB_DEFAULT_HEIGHT 1024
+#define VFB_DEFAULT_DEPTH 8
+#define VFB_DEFAULT_WHITEPIXEL 0
+#define VFB_DEFAULT_BLACKPIXEL 1
+#define VFB_DEFAULT_LINEBIAS 0
+#define XWD_WINDOW_NAME_LEN 60
+
+typedef struct
+{
+ int scrnum;
+ int width;
+ 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;
+
+#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[MAXSCREENS];
+static Bool vfbPixmapDepths[33];
+static char *pfbdir = NULL;
+typedef enum { NORMAL_MEMORY_FB, SHARED_MEMORY_FB, MMAPPED_FILE_FB } fbMemType;
+static fbMemType fbmemtype = NORMAL_MEMORY_FB;
+static char needswap = 0;
+static int lastScreen = -1;
+
+#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()
+{
+ int i;
+ vfbPixmapDepths[1] = TRUE; /* always need bitmaps */
+ for (i = 2; i <= 32; i++)
+ vfbPixmapDepths[i] = FALSE;
+}
+
+static void
+vfbInitializeDefaultScreens()
+{
+ int i;
+
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].scrnum = i;
+ vfbScreens[i].width = VFB_DEFAULT_WIDTH;
+ vfbScreens[i].height = VFB_DEFAULT_HEIGHT;
+ vfbScreens[i].depth = VFB_DEFAULT_DEPTH;
+ vfbScreens[i].blackPixel = VFB_DEFAULT_BLACKPIXEL;
+ vfbScreens[i].whitePixel = VFB_DEFAULT_WHITEPIXEL;
+ vfbScreens[i].lineBias = VFB_DEFAULT_LINEBIAS;
+ vfbScreens[i].pfbMemory = NULL;
+ }
+ vfbNumScreens = 1;
+}
+
+static int
+vfbBitsPerPixel(depth)
+ int depth;
+{
+ if (depth == 1) return 1;
+ else if (depth <= 8) return 8;
+ else if (depth <= 16) return 16;
+ else return 32;
+}
+
+void
+ddxGiveUp()
+{
+ 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, errno %d",
+ vfbScreens[i].mmap_file, errno);
+ }
+ }
+ 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, errno %d", errno);
+ }
+ }
+ break;
+#endif /* HAS_SHM */
+
+ case NORMAL_MEMORY_FB:
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ Xfree(vfbScreens[i].pXWDHeader);
+ }
+ break;
+ }
+}
+
+void
+AbortDDX()
+{
+ ddxGiveUp();
+}
+
+void
+OsVendorInit()
+{
+}
+
+void
+ddxUseMsg()
+{
+ ErrorF("-screen scrn WxHxD set screen's width, height, depth\n");
+ ErrorF("-pixdepths list-of-int support given pixmap depths\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 (argc, argv, i)
+ int argc;
+ char *argv[];
+ int i;
+{
+ static Bool firstTime = TRUE;
+
+ if (firstTime)
+ {
+ vfbInitializeDefaultScreens();
+ vfbInitializePixmapDepths();
+ firstTime = FALSE;
+ }
+
+ if (strcmp (argv[i], "-screen") == 0) /* -screen n WxHxD */
+ {
+ int screenNum;
+ if (i + 2 >= argc) UseMsg();
+ screenNum = atoi(argv[i+1]);
+ if (screenNum < 0 || screenNum >= MAXSCREENS)
+ {
+ ErrorF("Invalid screen number %d\n", screenNum);
+ UseMsg();
+ }
+ 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();
+ }
+
+ if (screenNum >= vfbNumScreens)
+ vfbNumScreens = screenNum + 1;
+ lastScreen = screenNum;
+ return 3;
+ }
+
+ if (strcmp (argv[i], "-pixdepths") == 0) /* -pixdepths list-of-depth */
+ {
+ int depth, ret = 1;
+
+ if (++i >= argc) UseMsg();
+ while ((i < argc) && (depth = atoi(argv[i++])) != 0)
+ {
+ if (depth < 0 || depth > 32)
+ {
+ ErrorF("Invalid pixmap depth %d\n", depth);
+ UseMsg();
+ }
+ vfbPixmapDepths[depth] = TRUE;
+ ret++;
+ }
+ return ret;
+ }
+
+ if (strcmp (argv[i], "-blackpixel") == 0) /* -blackpixel n */
+ {
+ Pixel pix;
+ if (++i >= argc) UseMsg();
+ pix = atoi(argv[i]);
+ if (-1 == lastScreen)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].blackPixel = pix;
+ }
+ }
+ else
+ {
+ vfbScreens[lastScreen].blackPixel = pix;
+ }
+ return 2;
+ }
+
+ if (strcmp (argv[i], "-whitepixel") == 0) /* -whitepixel n */
+ {
+ Pixel pix;
+ if (++i >= argc) UseMsg();
+ pix = atoi(argv[i]);
+ if (-1 == lastScreen)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].whitePixel = pix;
+ }
+ }
+ else
+ {
+ vfbScreens[lastScreen].whitePixel = pix;
+ }
+ return 2;
+ }
+
+ if (strcmp (argv[i], "-linebias") == 0) /* -linebias n */
+ {
+ unsigned int linebias;
+ if (++i >= argc) UseMsg();
+ linebias = atoi(argv[i]);
+ if (-1 == lastScreen)
+ {
+ int i;
+ for (i = 0; i < MAXSCREENS; i++)
+ {
+ vfbScreens[i].lineBias = linebias;
+ }
+ }
+ else
+ {
+ vfbScreens[lastScreen].lineBias = linebias;
+ }
+ return 2;
+ }
+
+#ifdef HAS_MMAP
+ if (strcmp (argv[i], "-fbdir") == 0) /* -fbdir directory */
+ {
+ if (++i >= argc) UseMsg();
+ 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;
+}
+
+#ifdef DDXTIME /* from ServerOSDefines */
+CARD32
+GetTimeInMillis()
+{
+ struct timeval tp;
+
+ X_GETTIMEOFDAY(&tp);
+ return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
+}
+#endif
+
+
+static Bool
+vfbMultiDepthCreateGC(pGC)
+ GCPtr pGC;
+{
+ switch (vfbBitsPerPixel(pGC->depth))
+ {
+ case 1: return mfbCreateGC (pGC);
+ case 8: return cfbCreateGC (pGC);
+ case 16: return cfb16CreateGC (pGC);
+ case 32: return cfb32CreateGC (pGC);
+ default: return FALSE;
+ }
+}
+
+static void
+vfbMultiDepthGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
+ DrawablePtr pDrawable; /* drawable from which to get bits */
+ int wMax; /* largest value of all *pwidths */
+ register DDXPointPtr ppt; /* points to start copying from */
+ int *pwidth; /* list of number of bits to copy */
+ int nspans; /* number of scanlines to copy */
+ char *pdstStart; /* where to put the bits */
+{
+ switch (pDrawable->bitsPerPixel) {
+ case 1:
+ mfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+ break;
+ case 8:
+ cfbGetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+ break;
+ case 16:
+ cfb16GetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+ break;
+ case 32:
+ cfb32GetSpans(pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
+ break;
+ }
+ return;
+}
+
+static void
+vfbMultiDepthGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine)
+ DrawablePtr pDrawable;
+ int sx, sy, w, h;
+ unsigned int format;
+ unsigned long planeMask;
+ char *pdstLine;
+{
+ switch (pDrawable->bitsPerPixel)
+ {
+ case 1:
+ mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
+ break;
+ case 8:
+ cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
+ break;
+ case 16:
+ cfb16GetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
+ break;
+ case 32:
+ cfb32GetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
+ break;
+ }
+}
+
+static ColormapPtr InstalledMaps[MAXSCREENS];
+
+static int
+vfbListInstalledColormaps(pScreen, pmaps)
+ ScreenPtr pScreen;
+ Colormap *pmaps;
+{
+ /* By the time we are processing requests, we can guarantee that there
+ * is always a colormap installed */
+ *pmaps = InstalledMaps[pScreen->myNum]->mid;
+ return (1);
+}
+
+
+static void
+vfbInstallColormap(pmap)
+ ColormapPtr pmap;
+{
+ int index = pmap->pScreen->myNum;
+ ColormapPtr oldpmap = InstalledMaps[index];
+
+ 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 */
+ InstalledMaps[index] = 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 *)ALLOCATE_LOCAL(entries * sizeof(Pixel));
+ prgb = (xrgb *)ALLOCATE_LOCAL(entries * sizeof(xrgb));
+ defs = (xColorItem *)ALLOCATE_LOCAL(entries * sizeof(xColorItem));
+
+ for (i = 0; i < entries; i++) ppix[i] = i;
+ /* XXX truecolor */
+ QueryColors(pmap, entries, ppix, prgb);
+
+ 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);
+
+ DEALLOCATE_LOCAL(ppix);
+ DEALLOCATE_LOCAL(prgb);
+ DEALLOCATE_LOCAL(defs);
+ }
+}
+
+static void
+vfbUninstallColormap(pmap)
+ ColormapPtr pmap;
+{
+ ColormapPtr curpmap = InstalledMaps[pmap->pScreen->myNum];
+
+ if(pmap == curpmap)
+ {
+ if (pmap->mid != pmap->pScreen->defColormap)
+ {
+ curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
+ RT_COLORMAP);
+ (*pmap->pScreen->InstallColormap)(curpmap);
+ }
+ }
+}
+
+static void
+vfbStoreColors(pmap, ndef, pdefs)
+ ColormapPtr pmap;
+ int ndef;
+ xColorItem *pdefs;
+{
+ XWDColor *pXWDCmap;
+ int i;
+
+ if (pmap != InstalledMaps[pmap->pScreen->myNum]) 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(pScreen, on)
+ ScreenPtr pScreen;
+ int on;
+{
+ return TRUE;
+}
+
+#ifdef HAS_MMAP
+
+/* this flushes any changes to the screens out to the mmapped file */
+static void
+vfbBlockHandler(blockData, pTimeout, pReadmask)
+ 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, errno %d", errno);
+ }
+ }
+}
+
+
+static void
+vfbWakeupHandler(blockData, result, pReadmask)
+ pointer blockData;
+ int result;
+ pointer pReadmask;
+{
+}
+
+
+static void
+vfbAllocateMmappedFramebuffer(pvfb)
+ vfbScreenInfoPtr pvfb;
+{
+#define DUMMY_BUFFER_SIZE 65536
+ char dummyBuffer[DUMMY_BUFFER_SIZE];
+ int currentFileSize, writeThisTime;
+
+ sprintf(pvfb->mmap_file, "%s/Xvfb_screen%d", pfbdir, pvfb->scrnum);
+ if (-1 == (pvfb->mmap_fd = open(pvfb->mmap_file, O_CREAT|O_RDWR, 0666)))
+ {
+ perror("open");
+ ErrorF("open %s failed, errno %d", pvfb->mmap_file, errno);
+ return;
+ }
+
+ /* Extend the file to be the proper size */
+
+ bzero(dummyBuffer, 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, errno %d", pvfb->mmap_file, 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 == (int)pvfb->pXWDHeader)
+ {
+ perror("mmap");
+ ErrorF("mmap %s failed, errno %d", pvfb->mmap_file, errno);
+ pvfb->pXWDHeader = NULL;
+ return;
+ }
+
+ if (!RegisterBlockAndWakeupHandlers(vfbBlockHandler, vfbWakeupHandler,
+ NULL))
+ {
+ pvfb->pXWDHeader = NULL;
+ }
+}
+#endif /* HAS_MMAP */
+
+
+#ifdef HAS_SHM
+static void
+vfbAllocateSharedMemoryFramebuffer(pvfb)
+ 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, errno %d", pvfb->sizeInBytes, errno);
+ return;
+ }
+
+ /* try to attach it */
+
+ pvfb->pXWDHeader = (XWDFileHeader *)shmat(pvfb->shmid, 0, 0);
+ if (-1 == (int)pvfb->pXWDHeader)
+ {
+ perror("shmat");
+ ErrorF("shmat failed, errno %d", errno);
+ pvfb->pXWDHeader = NULL;
+ return;
+ }
+
+ ErrorF("screen %d shmid %d\n", pvfb->scrnum, pvfb->shmid);
+}
+#endif /* HAS_SHM */
+
+static char *
+vfbAllocateFramebufferMemory(pvfb)
+ vfbScreenInfoPtr pvfb;
+{
+ if (pvfb->pfbMemory) return pvfb->pfbMemory; /* already done */
+
+ if (pvfb->bitsPerPixel == 1)
+ pvfb->sizeInBytes = (pvfb->paddedWidth * pvfb->height);
+ else
+ pvfb->sizeInBytes = pvfb->paddedWidth * pvfb->height *
+ (pvfb->bitsPerPixel/8);
+
+ /* 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;
+#endif
+
+#ifdef HAS_SHM
+ case SHARED_MEMORY_FB: vfbAllocateSharedMemoryFramebuffer(pvfb); break;
+#endif
+
+ case NORMAL_MEMORY_FB:
+ pvfb->pXWDHeader = (XWDFileHeader *)Xalloc(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(pScreen)
+ ScreenPtr pScreen;
+{
+ vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
+ XWDFileHeader *pXWDHeader = pvfb->pXWDHeader;
+ char hostname[XWD_WINDOW_NAME_LEN];
+ VisualPtr pVisual;
+ 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->paddedWidth;
+ 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 (ppScreen, x, y)
+ ScreenPtr *ppScreen;
+ int *x, *y;
+{
+ return FALSE;
+}
+
+static void
+vfbCrossScreen (pScreen, entering)
+ ScreenPtr pScreen;
+ Bool entering;
+{
+}
+
+static miPointerScreenFuncRec vfbPointerCursorFuncs =
+{
+ vfbCursorOffScreen,
+ vfbCrossScreen,
+ miPointerWarpCursor
+};
+
+static Bool
+vfbScreenInit(index, pScreen, argc, argv)
+ int index;
+ ScreenPtr pScreen;
+ int argc;
+ char ** argv;
+{
+ vfbScreenInfoPtr pvfb = &vfbScreens[index];
+ int dpix = 100, dpiy = 100;
+ int ret;
+ char *pbits;
+
+ pvfb->paddedWidth = PixmapBytePad(pvfb->width, pvfb->depth);
+ pvfb->bitsPerPixel = vfbBitsPerPixel(pvfb->depth);
+ pbits = vfbAllocateFramebufferMemory(pvfb);
+ if (!pbits) return FALSE;
+
+ switch (pvfb->bitsPerPixel)
+ {
+ case 1:
+ ret = mfbScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
+ dpix, dpiy, pvfb->paddedWidth * 8);
+ break;
+ case 8:
+ ret = cfbScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
+ dpix, dpiy, pvfb->paddedWidth);
+ break;
+ case 16:
+ ret = cfb16ScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
+ dpix, dpiy, pvfb->paddedWidth);
+ break;
+ case 32:
+ ret = cfb32ScreenInit(pScreen, pbits, pvfb->width, pvfb->height,
+ dpix, dpiy, pvfb->paddedWidth);
+ break;
+ default:
+ return FALSE;
+ }
+
+ if (!ret) return FALSE;
+
+ pScreen->CreateGC = vfbMultiDepthCreateGC;
+ pScreen->GetImage = vfbMultiDepthGetImage;
+ pScreen->GetSpans = vfbMultiDepthGetSpans;
+
+ 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;
+
+ if (pvfb->bitsPerPixel == 1)
+ {
+ ret = mfbCreateDefColormap(pScreen);
+ }
+ else
+ {
+ ret = cfbCreateDefColormap(pScreen);
+ }
+
+ miSetZeroLineBias(pScreen, pvfb->lineBias);
+
+ return ret;
+
+} /* end vfbScreenInit */
+
+
+void
+InitOutput(screenInfo, argc, argv)
+ ScreenInfo *screenInfo;
+ int argc;
+ char **argv;
+{
+ int i;
+ int NumFormats = 0;
+ FILE *pf = stderr;
+
+ /* initialize pixmap formats */
+
+ /* must have a pixmap depth to match every screen depth */
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ vfbPixmapDepths[vfbScreens[i].depth] = 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 */
+
+ for (i = 0; i < vfbNumScreens; i++)
+ {
+ if (-1 == AddScreen(vfbScreenInit, argc, argv))
+ {
+ FatalError("Couldn't add screen %d", i);
+ }
+ }
+
+} /* end InitOutput */
+
+/* this is just to get the server to link on AIX */
+#ifdef AIXV3
+int SelectWaitTime = 10000; /* usec */
+#endif
+
diff --git a/hw/vfb/Xvfb.man.pre b/hw/vfb/Xvfb.man.pre
new file mode 100644
index 000000000..3d8d86156
--- /dev/null
+++ b/hw/vfb/Xvfb.man.pre
@@ -0,0 +1,128 @@
+.\" $Xorg: Xvfb.man,v 1.4 2001/02/09 02:04:45 xorgcvs Exp $
+.\" 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.
+.TH XVFB 1 "Release 6.4" "X Version 11"
+.SH NAME
+Xvfb \- virtual framebuffer X server for X Version 11
+.SH SYNOPSIS
+.B Xvfb
+[ option ] ...
+.SH DESCRIPTION
+.I Xvfb
+is an X server that can run on machines with no display hardware
+and no physical input devices. It emulates a dumb framebuffer using
+virtual memory.
+.PP
+The primary use of this server was intended to be server testing. The
+mfb or cfb code for any depth can be exercised with this server
+without the need for real hardware that supports the desired depths.
+The X community has found many other novel uses for \fIXvfb\fP,
+including testing clients against unusual depths and screen
+configurations, doing batch processing with \fIXvfb\fP as a background
+rendering engine, load testing, as an aid to porting the X server to a
+new platform, and providing an unobtrusive way to run applications
+that don't really need an X server but insist on having one anyway.
+.SH BUILDING
+To build \fIXvfb\fP, put the following in your host.def and remake.
+.PP
+#define BuildServer YES /* if you aren't already building other servers */
+.br
+#define XVirtualFramebufferServer YES
+
+.SH OPTIONS
+.PP
+In addition to the normal server options described in the \fIXserver(1)\fP
+manual page, \fIXvfb\fP accepts the following command line switches:
+.TP 4
+.B "\-screen \fIscreennum\fP \fIWxHxD\fP"
+This option creates screen \fIscreennum\fP and sets its width, height,
+and depth to W, H, and D respectively. By default, only screen 0 exists
+and has the dimensions 1280x1024x8.
+.TP 4
+.B "\-pixdepths \fIlist-of-depths\fP"
+This option specifies a list of pixmap depths that the server should
+support in addition to the depths implied by the supported screens.
+\fIlist-of-depths\fP is a space-separated list of integers that can
+have values from 1 to 32.
+.TP 4
+.B "\-fbdir \fIframebuffer-directory\fP"
+This option specifies the directory in which the memory mapped files
+containing the framebuffer memory should be created.
+See FILES.
+This option only exists on machines that have the mmap and msync system
+calls.
+.TP 4
+.B "\-shmem"
+This option specifies that the framebuffer should be put in shared memory.
+The shared memory ID for each screen will be printed by the server.
+The shared memory is in xwd format.
+This option only exists on machines that support the System V shared memory
+interface.
+.PP
+If neither \fB\-shmem\fP nor \fB\-fbdir\fP is specified,
+the framebuffer memory will be allocated with malloc().
+.TP 4
+.B "\-linebias \fIn\fP"
+This option specifies how to adjust the pixelization of thin lines.
+The value \fIn\fP is a bitmask of octants in which to prefer an axial
+step when the Bresenham error term is exactly zero. See the file
+Xserver/mi/miline.h for more information. This option is probably only useful
+to server developers to experiment with the range of line pixelization
+possible with the cfb and mfb code.
+.TP 4
+.B "\-blackpixel \fIpixel-value\fP, \-whitepixel \fIpixel-value\fP"
+These options specify the black and white pixel values the server should use.
+.SH FILES
+The following files are created if the \-fbdir option is given.
+.TP 4
+\fIframebuffer-directory\fP/Xvfb_screen<n>
+Memory mapped file containing screen n's framebuffer memory, one file
+per screen. The file is in xwd format. Thus, taking a full-screen
+snapshot can be done with a file copy command, and the resulting
+snapshot will even contain the cursor image.
+.SH EXAMPLES
+.TP 8
+Xvfb :1 -screen 0 1600x1200x32
+The server will listen for connections as server number 1, and screen 0
+will be depth 32 1600x1200.
+.TP 8
+Xvfb :1 -screen 1 1600x1200x16
+The server will listen for connections as server number 1, will have the
+default screen configuration (one screen, 1280x1024x8), and screen 1
+will be depth 16 1600x1200.
+.TP 8
+Xvfb -pixdepths 3 27 -fbdir /usr/tmp
+The server will listen for connections as server number 0, will have the
+default screen configuration (one screen, 1280x1024x8),
+will also support pixmap
+depths of 3 and 27,
+and will use memory mapped files in /usr/tmp for the framebuffer.
+.TP 8
+xwud -in /usr/tmp/Xvfb_screen0
+Displays screen 0 of the server started by the preceding example.
+.SH "SEE ALSO"
+.PP
+X(1), Xserver(1), xwd(1), xwud(1), XWDFile.h
+.SH AUTHORS
+David P. Wiggins, The Open Group, Inc.
diff --git a/hw/vfb/lk201kbd.h b/hw/vfb/lk201kbd.h
new file mode 100644
index 000000000..9b4090ed0
--- /dev/null
+++ b/hw/vfb/lk201kbd.h
@@ -0,0 +1,159 @@
+/***********************************************************
+
+Copyright 1987, 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.
+
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+/* $Xorg: lk201kbd.h,v 1.4 2001/02/09 02:04:45 xorgcvs Exp $ */
+
+#define MIN_LK201_KEY 86
+#define MAX_LK201_KEY 251
+#define LK201_GLYPHS_PER_KEY 2
+
+#define KEY_F1 86
+#define KEY_F2 87
+#define KEY_F3 88
+#define KEY_F4 89
+#define KEY_F5 90
+#define KEY_F6 100
+#define KEY_F7 101
+#define KEY_F8 102
+#define KEY_F9 103
+#define KEY_F10 104
+#define KEY_F11 113
+#define KEY_F12 114
+#define KEY_F13 115
+#define KEY_F14 116
+#define KEY_HELP 124
+#define KEY_MENU 125
+#define KEY_F17 128
+#define KEY_F18 129
+#define KEY_F19 130
+#define KEY_F20 131
+#define KEY_FIND 138
+#define KEY_INSERT_HERE 139
+#define KEY_REMOVE 140
+#define KEY_SELECT 141
+#define KEY_PREV_SCREEN 142
+#define KEY_NEXT_SCREEN 143
+#define KEY_KP_0 146 /* key pad */
+#define KEY_KP_PERIOD 148 /* key pad */
+#define KEY_KP_ENTER 149 /* key pad */
+#define KEY_KP_1 150 /* key pad */
+#define KEY_KP_2 151 /* key pad */
+#define KEY_KP_3 152 /* key pad */
+#define KEY_KP_4 153 /* key pad */
+#define KEY_KP_5 154 /* key pad */
+#define KEY_KP_6 155 /* key pad */
+#define KEY_KP_COMMA 156 /* key pad */
+#define KEY_KP_7 157 /* key pad */
+#define KEY_KP_8 158 /* key pad */
+#define KEY_KP_9 159 /* key pad */
+#define KEY_KP_HYPHEN 160
+#define KEY_KP_PF1 161
+#define KEY_KP_PF2 162
+#define KEY_KP_PF3 163
+#define KEY_KP_PF4 164
+#define KEY_LEFT 167
+#define KEY_RIGHT 168
+#define KEY_DOWN 169
+#define KEY_UP 170
+#define KEY_SHIFT 174
+#define KEY_CTRL 175
+#define KEY_LOCK 176
+#define KEY_COMPOSE 177
+#define KEY_APPLE 177
+#define KEY_META 177
+#define KEY_DELETE 188
+#define KEY_RETURN 189
+#define KEY_TAB 190
+#define KEY_TILDE 191
+#define KEY_TR_1 192 /* Top Row */
+#define KEY_Q 193
+#define KEY_A 194
+#define KEY_Z 195
+#define KEY_TR_2 197
+#define KEY_W 198
+#define KEY_S 199
+#define KEY_X 200
+#define KEY_LANGLE_RANGLE 201 /* xxx */
+#define KEY_TR_3 203
+#define KEY_E 204
+#define KEY_D 205
+#define KEY_C 206
+#define KEY_TR_4 208
+#define KEY_R 209
+#define KEY_F 210
+#define KEY_V 211
+#define KEY_SPACE 212
+#define KEY_TR_5 214
+#define KEY_T 215
+#define KEY_G 216
+#define KEY_B 217
+#define KEY_TR_6 219
+#define KEY_Y 220
+#define KEY_H 221
+#define KEY_N 222
+#define KEY_TR_7 224
+#define KEY_U 225
+#define KEY_J 226
+#define KEY_M 227
+#define KEY_TR_8 229
+#define KEY_I 230
+#define KEY_K 231
+#define KEY_COMMA 232 /* xxx */
+#define KEY_TR_9 234
+#define KEY_O 235
+#define KEY_L 236
+#define KEY_PERIOD 237 /* xxx */
+#define KEY_TR_0 239
+#define KEY_P 240
+#define KEY_SEMICOLON 242 /* xxx */
+#define KEY_QMARK 243
+#define KEY_PLUS 245 /* xxx */
+#define KEY_RBRACE 246
+#define KEY_VBAR 247 /* xxx */
+#define KEY_UBAR 249 /* xxx */
+#define KEY_LBRACE 250
+#define KEY_QUOTE 251