This gives x11spice access to a modern virtual/offscreen frame buffer driver for the Xorg X server. We will then make slight revisions to make it more suitable for use with Spice. The overall result should be a more functional stack, as compared to the existing xf86-video-qxl driver, as we gain a wide range of Mesa features for free. It also simplifies the overall process. This is from https://gitlab.freedesktop.org/xorg/driver/xf86-video-dummy as of 850c0516. Signed-off-by: Jeremy White <jwhite@xxxxxxxxxxxxxxx> --- v2: Provide a specific URL for reference to the upstream xorg driver. --- spice-video-dummy/COPYING | 2 + spice-video-dummy/Makefile.am | 31 ++ spice-video-dummy/README.md | 18 + spice-video-dummy/autogen.sh | 17 + spice-video-dummy/configure.ac | 72 ++++ spice-video-dummy/src/Makefile.am | 39 ++ spice-video-dummy/src/compat-api.h | 101 +++++ spice-video-dummy/src/dummy.h | 59 +++ spice-video-dummy/src/dummy_cursor.c | 102 +++++ spice-video-dummy/src/dummy_driver.c | 740 +++++++++++++++++++++++++++++++++++ 10 files changed, 1181 insertions(+) create mode 100644 spice-video-dummy/COPYING create mode 100644 spice-video-dummy/Makefile.am create mode 100644 spice-video-dummy/README.md create mode 100755 spice-video-dummy/autogen.sh create mode 100644 spice-video-dummy/configure.ac create mode 100644 spice-video-dummy/src/Makefile.am create mode 100644 spice-video-dummy/src/compat-api.h create mode 100644 spice-video-dummy/src/dummy.h create mode 100644 spice-video-dummy/src/dummy_cursor.c create mode 100644 spice-video-dummy/src/dummy_driver.c diff --git a/spice-video-dummy/COPYING b/spice-video-dummy/COPYING new file mode 100644 index 0000000..3c1ef48 --- /dev/null +++ b/spice-video-dummy/COPYING @@ -0,0 +1,2 @@ +Copyright 2002, SuSE Linux AG, Author: Egbert Eich + diff --git a/spice-video-dummy/Makefile.am b/spice-video-dummy/Makefile.am new file mode 100644 index 0000000..1a10a1c --- /dev/null +++ b/spice-video-dummy/Makefile.am @@ -0,0 +1,31 @@ +# Copyright 2005 Adam Jackson. +# +# 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, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +# ADAM JACKSON 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. + +SUBDIRS = src +MAINTAINERCLEANFILES = ChangeLog + +.PHONY: ChangeLog + +ChangeLog: + $(CHANGELOG_CMD) + +dist-hook: ChangeLog + +EXTRA_DIST = README.md diff --git a/spice-video-dummy/README.md b/spice-video-dummy/README.md new file mode 100644 index 0000000..2a84bc3 --- /dev/null +++ b/spice-video-dummy/README.md @@ -0,0 +1,18 @@ +xf86-video-dummy - virtual/offscreen frame buffer driver for the Xorg X server +------------------------------------------------------------------------------ + +All questions regarding this software should be directed at the +Xorg mailing list: + + https://lists.x.org/mailman/listinfo/xorg + +The master development code repository can be found at: + + https://gitlab.freedesktop.org/xorg/driver/xf86-video-dummy + +Please submit bug reports and requests to merge patches there. + +For patch submission instructions, see: + + https://www.x.org/wiki/Development/Documentation/SubmittingPatches + diff --git a/spice-video-dummy/autogen.sh b/spice-video-dummy/autogen.sh new file mode 100755 index 0000000..9b9f7e7 --- /dev/null +++ b/spice-video-dummy/autogen.sh @@ -0,0 +1,17 @@ +#! /bin/sh + +srcdir=`dirname "$0"` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd "$srcdir" + +autoreconf -v --install || exit 1 +cd "$ORIGDIR" || exit $? + +git config --local --get format.subjectPrefix >/dev/null 2>&1 || + git config --local format.subjectPrefix "PATCH xf86-video-dummy" + +if test -z "$NOCONFIGURE"; then + exec "$srcdir"/configure "$@" +fi diff --git a/spice-video-dummy/configure.ac b/spice-video-dummy/configure.ac new file mode 100644 index 0000000..2ca0327 --- /dev/null +++ b/spice-video-dummy/configure.ac @@ -0,0 +1,72 @@ +# Copyright 2005 Adam Jackson. +# +# 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, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +# ADAM JACKSON 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. +# +# Process this file with autoconf to produce a configure script + +# Initialize Autoconf +AC_PREREQ([2.60]) +AC_INIT([xf86-video-dummy], + [0.3.8], + [https://gitlab.freedesktop.org/xorg/driver/xf86-video-dummy/issues], + [xf86-video-dummy]) +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_AUX_DIR(.) + +# Initialize Automake +AM_INIT_AUTOMAKE([foreign dist-bzip2]) + +# Require xorg-macros: XORG_DEFAULT_OPTIONS +m4_ifndef([XORG_MACROS_VERSION], + [m4_fatal([must install xorg-macros 1.3 or later before running autoconf/autogen])]) +XORG_MACROS_VERSION(1.3) +XORG_DEFAULT_OPTIONS + +# Initialize libtool +AC_DISABLE_STATIC +AC_PROG_LIBTOOL + +AH_TOP([#include "xorg-server.h"]) + +# Define a configure option for an alternate module directory +AC_ARG_WITH(xorg-module-dir, [ --with-xorg-module-dir=DIR ], + [ moduledir="$withval" ], + [ moduledir="$libdir/xorg/modules" ]) +AC_SUBST(moduledir) + + +# Store the list of server defined optional extensions in REQUIRED_MODULES +XORG_DRIVER_CHECK_EXT(RANDR, randrproto) +XORG_DRIVER_CHECK_EXT(RENDER, renderproto) + +# Obtain compiler/linker options for the driver dependencies +PKG_CHECK_MODULES(XORG, [xorg-server >= 1.4.99.901] xproto fontsproto $REQUIRED_MODULES) + +# Checks for libraries. + + +DRIVER_NAME=dummy +AC_SUBST([DRIVER_NAME]) + +AC_CONFIG_FILES([ + Makefile + src/Makefile +]) +AC_OUTPUT diff --git a/spice-video-dummy/src/Makefile.am b/spice-video-dummy/src/Makefile.am new file mode 100644 index 0000000..c0d82e0 --- /dev/null +++ b/spice-video-dummy/src/Makefile.am @@ -0,0 +1,39 @@ +# Copyright 2005 Adam Jackson. +# +# 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, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +# ADAM JACKSON 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. + + +# this is obnoxious: +# -module lets us name the module exactly how we want +# -avoid-version prevents gratuitous .0.0.0 version numbers on the end +# _ladir passes a dummy rpath to libtool so the thing will actually link +# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc. + +AM_CFLAGS = $(XORG_CFLAGS) $(PCIACCESS_CFLAGS) + +dummy_drv_la_LTLIBRARIES = dummy_drv.la +dummy_drv_la_LDFLAGS = -module -avoid-version +dummy_drv_la_LIBADD = $(XORG_LIBS) +dummy_drv_ladir = @moduledir@/drivers + +dummy_drv_la_SOURCES = \ + compat-api.h \ + dummy_cursor.c \ + dummy_driver.c \ + dummy.h diff --git a/spice-video-dummy/src/compat-api.h b/spice-video-dummy/src/compat-api.h new file mode 100644 index 0000000..b74a582 --- /dev/null +++ b/spice-video-dummy/src/compat-api.h @@ -0,0 +1,101 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: Dave Airlie <airlied@xxxxxxxxxx> + */ + +/* this file provides API compat between server post 1.13 and pre it, + it should be reused inside as many drivers as possible */ +#ifndef COMPAT_API_H +#define COMPAT_API_H + +#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR +#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum] +#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p +#endif + +#ifndef XF86_HAS_SCRN_CONV +#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum] +#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex] +#endif + +#ifndef XF86_SCRN_INTERFACE + +#define SCRN_ARG_TYPE int +#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)] + +#define SCREEN_ARG_TYPE int +#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)] + +#define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv + +#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask +#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask + +#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen +#define CLOSE_SCREEN_ARGS scrnIndex, pScreen + +#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags +#define ADJUST_FRAME_ARGS(arg, x, y) (arg)->scrnIndex, x, y, 0 + +#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags +#define SWITCH_MODE_ARGS(arg, m) (arg)->scrnIndex, m, 0 + +#define FREE_SCREEN_ARGS_DECL int arg, int flags +#define FREE_SCREEN_ARGS(x) (x)->scrnIndex, 0 + +#define VT_FUNC_ARGS_DECL int arg, int flags +#define VT_FUNC_ARGS(flags) pScrn->scrnIndex, (flags) + +#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex) +#else +#define SCRN_ARG_TYPE ScrnInfoPtr +#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1) + +#define SCREEN_ARG_TYPE ScreenPtr +#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1) + +#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv + +#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask +#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask + +#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen +#define CLOSE_SCREEN_ARGS pScreen + +#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y +#define ADJUST_FRAME_ARGS(arg, x, y) arg, x, y + +#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode +#define SWITCH_MODE_ARGS(arg, m) arg, m + +#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg +#define FREE_SCREEN_ARGS(x) (x) + +#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg +#define VT_FUNC_ARGS(flags) pScrn + +#define XF86_ENABLEDISABLEFB_ARG(x) (x) + +#endif + +#endif diff --git a/spice-video-dummy/src/dummy.h b/spice-video-dummy/src/dummy.h new file mode 100644 index 0000000..8e7c43b --- /dev/null +++ b/spice-video-dummy/src/dummy.h @@ -0,0 +1,59 @@ + +/* All drivers should typically include these */ +#include "xf86.h" +#include "xf86_OSproc.h" + +#include "xf86Cursor.h" + +#ifdef XvExtension +#include "xf86xv.h" +#include <X11/extensions/Xv.h> +#endif +#include <string.h> + +#include "compat-api.h" + +/* Supported chipsets */ +typedef enum { + DUMMY_CHIP +} DUMMYType; + +/* function prototypes */ + +extern Bool DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL); +extern void DUMMYAdjustFrame(ADJUST_FRAME_ARGS_DECL); + +/* in dummy_cursor.c */ +extern Bool DUMMYCursorInit(ScreenPtr pScrn); +extern void DUMMYShowCursor(ScrnInfoPtr pScrn); +extern void DUMMYHideCursor(ScrnInfoPtr pScrn); + +/* globals */ +typedef struct _color +{ + int red; + int green; + int blue; +} dummy_colors; + +typedef struct dummyRec +{ + /* options */ + OptionInfoPtr Options; + Bool swCursor; + /* proc pointer */ + CloseScreenProcPtr CloseScreen; + xf86CursorInfoPtr CursorInfo; + + Bool DummyHWCursorShown; + int cursorX, cursorY; + int cursorFG, cursorBG; + + dummy_colors colors[1024]; + Bool (*CreateWindow)() ; /* wrapped CreateWindow */ + Bool prop; +} DUMMYRec, *DUMMYPtr; + +/* The privates of the DUMMY driver */ +#define DUMMYPTR(p) ((DUMMYPtr)((p)->driverPrivate)) + diff --git a/spice-video-dummy/src/dummy_cursor.c b/spice-video-dummy/src/dummy_cursor.c new file mode 100644 index 0000000..d7c67c6 --- /dev/null +++ b/spice-video-dummy/src/dummy_cursor.c @@ -0,0 +1,102 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* All drivers should typically include these */ +#include "xf86.h" +#include "xf86_OSproc.h" + +#include "xf86Cursor.h" +#include "cursorstr.h" +/* Driver specific headers */ +#include "dummy.h" + +static void +dummyShowCursor(ScrnInfoPtr pScrn) +{ + DUMMYPtr dPtr = DUMMYPTR(pScrn); + + /* turn cursor on */ + dPtr->DummyHWCursorShown = TRUE; +} + +static void +dummyHideCursor(ScrnInfoPtr pScrn) +{ + DUMMYPtr dPtr = DUMMYPTR(pScrn); + + /* + * turn cursor off + * + */ + dPtr->DummyHWCursorShown = FALSE; +} + +#define MAX_CURS 64 + +static void +dummySetCursorPosition(ScrnInfoPtr pScrn, int x, int y) +{ + DUMMYPtr dPtr = DUMMYPTR(pScrn); + + dPtr->cursorX = x; + dPtr->cursorY = y; +} + +static void +dummySetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) +{ + DUMMYPtr dPtr = DUMMYPTR(pScrn); + + dPtr->cursorFG = fg; + dPtr->cursorBG = bg; +} + +static void +dummyLoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) +{ +} + +static Bool +dummyUseHWCursor(ScreenPtr pScr, CursorPtr pCurs) +{ + DUMMYPtr dPtr = DUMMYPTR(xf86ScreenToScrn(pScr)); + return(!dPtr->swCursor); +} + +#if 0 +static unsigned char* +dummyRealizeCursor(xf86CursorInfoPtr infoPtr, CursorPtr pCurs) +{ + return NULL; +} +#endif + +Bool +DUMMYCursorInit(ScreenPtr pScreen) +{ + DUMMYPtr dPtr = DUMMYPTR(xf86ScreenToScrn(pScreen)); + + xf86CursorInfoPtr infoPtr; + infoPtr = xf86CreateCursorInfoRec(); + if(!infoPtr) return FALSE; + + dPtr->CursorInfo = infoPtr; + + infoPtr->MaxHeight = 64; + infoPtr->MaxWidth = 64; + infoPtr->Flags = HARDWARE_CURSOR_TRUECOLOR_AT_8BPP; + + infoPtr->SetCursorColors = dummySetCursorColors; + infoPtr->SetCursorPosition = dummySetCursorPosition; + infoPtr->LoadCursorImage = dummyLoadCursorImage; + infoPtr->HideCursor = dummyHideCursor; + infoPtr->ShowCursor = dummyShowCursor; + infoPtr->UseHWCursor = dummyUseHWCursor; +/* infoPtr->RealizeCursor = dummyRealizeCursor; */ + + return(xf86InitCursor(pScreen, infoPtr)); +} + + + diff --git a/spice-video-dummy/src/dummy_driver.c b/spice-video-dummy/src/dummy_driver.c new file mode 100644 index 0000000..b4b42f7 --- /dev/null +++ b/spice-video-dummy/src/dummy_driver.c @@ -0,0 +1,740 @@ + +/* + * Copyright 2002, SuSE Linux AG, Author: Egbert Eich + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* All drivers should typically include these */ +#include "xf86.h" +#include "xf86_OSproc.h" + +/* All drivers initialising the SW cursor need this */ +#include "mipointer.h" + +/* All drivers using the mi colormap manipulation need this */ +#include "micmap.h" + +/* identifying atom needed by magnifiers */ +#include <X11/Xatom.h> +#include "property.h" + +#include "xf86cmap.h" + +#include "xf86fbman.h" + +#include "fb.h" + +#include "picturestr.h" + +/* + * Driver data structures. + */ +#include "dummy.h" + +/* These need to be checked */ +#include <X11/X.h> +#include <X11/Xproto.h> +#include "scrnintstr.h" +#include "servermd.h" + +/* Mandatory functions */ +static const OptionInfoRec * DUMMYAvailableOptions(int chipid, int busid); +static void DUMMYIdentify(int flags); +static Bool DUMMYProbe(DriverPtr drv, int flags); +static Bool DUMMYPreInit(ScrnInfoPtr pScrn, int flags); +static Bool DUMMYScreenInit(SCREEN_INIT_ARGS_DECL); +static Bool DUMMYEnterVT(VT_FUNC_ARGS_DECL); +static void DUMMYLeaveVT(VT_FUNC_ARGS_DECL); +static Bool DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL); +static Bool DUMMYCreateWindow(WindowPtr pWin); +static void DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL); +static ModeStatus DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, + Bool verbose, int flags); +static Bool DUMMYSaveScreen(ScreenPtr pScreen, int mode); + +/* Internally used functions */ +static Bool dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, + pointer ptr); + + +/* static void DUMMYDisplayPowerManagementSet(ScrnInfoPtr pScrn, */ +/* int PowerManagementMode, int flags); */ + +#define DUMMY_VERSION 4000 +#define DUMMY_NAME "DUMMY" +#define DUMMY_DRIVER_NAME "dummy" + +#define DUMMY_MAJOR_VERSION PACKAGE_VERSION_MAJOR +#define DUMMY_MINOR_VERSION PACKAGE_VERSION_MINOR +#define DUMMY_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL + +#define DUMMY_MAX_WIDTH 32767 +#define DUMMY_MAX_HEIGHT 32767 + +/* + * This is intentionally screen-independent. It indicates the binding + * choice made in the first PreInit. + */ +static int pix24bpp = 0; + + +/* + * This contains the functions needed by the server after loading the driver + * module. It must be supplied, and gets passed back by the SetupProc + * function in the dynamic case. In the static case, a reference to this + * is compiled in, and this requires that the name of this DriverRec be + * an upper-case version of the driver name. + */ + +_X_EXPORT DriverRec DUMMY = { + DUMMY_VERSION, + DUMMY_DRIVER_NAME, + DUMMYIdentify, + DUMMYProbe, + DUMMYAvailableOptions, + NULL, + 0, + dummyDriverFunc +}; + +static SymTabRec DUMMYChipsets[] = { + { DUMMY_CHIP, "dummy" }, + { -1, NULL } +}; + +typedef enum { + OPTION_SW_CURSOR +} DUMMYOpts; + +static const OptionInfoRec DUMMYOptions[] = { + { OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE }, + { -1, NULL, OPTV_NONE, {0}, FALSE } +}; + +#ifdef XFree86LOADER + +static MODULESETUPPROTO(dummySetup); + +static XF86ModuleVersionInfo dummyVersRec = +{ + "dummy", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + DUMMY_MAJOR_VERSION, DUMMY_MINOR_VERSION, DUMMY_PATCHLEVEL, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0,0,0,0} +}; + +/* + * This is the module init data. + * Its name has to be the driver name followed by ModuleData + */ +_X_EXPORT XF86ModuleData dummyModuleData = { &dummyVersRec, dummySetup, NULL }; + +static pointer +dummySetup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = FALSE; + + if (!setupDone) { + setupDone = TRUE; + xf86AddDriver(&DUMMY, module, HaveDriverFuncs); + + /* + * Modules that this driver always requires can be loaded here + * by calling LoadSubModule(). + */ + + /* + * The return value must be non-NULL on success even though there + * is no TearDownProc. + */ + return (pointer)1; + } else { + if (errmaj) *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +#endif /* XFree86LOADER */ + +static Bool +DUMMYGetRec(ScrnInfoPtr pScrn) +{ + /* + * Allocate a DUMMYRec, and hook it into pScrn->driverPrivate. + * pScrn->driverPrivate is initialised to NULL, so we can check if + * the allocation has already been done. + */ + if (pScrn->driverPrivate != NULL) + return TRUE; + + pScrn->driverPrivate = xnfcalloc(sizeof(DUMMYRec), 1); + + if (pScrn->driverPrivate == NULL) + return FALSE; + return TRUE; +} + +static void +DUMMYFreeRec(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate == NULL) + return; + free(pScrn->driverPrivate); + pScrn->driverPrivate = NULL; +} + +static const OptionInfoRec * +DUMMYAvailableOptions(int chipid, int busid) +{ + return DUMMYOptions; +} + +/* Mandatory */ +static void +DUMMYIdentify(int flags) +{ + xf86PrintChipsets(DUMMY_NAME, "Driver for Dummy chipsets", + DUMMYChipsets); +} + +/* Mandatory */ +static Bool +DUMMYProbe(DriverPtr drv, int flags) +{ + Bool foundScreen = FALSE; + int numDevSections, numUsed; + GDevPtr *devSections; + int i; + + if (flags & PROBE_DETECT) + return FALSE; + /* + * Find the config file Device sections that match this + * driver, and return if there are none. + */ + if ((numDevSections = xf86MatchDevice(DUMMY_DRIVER_NAME, + &devSections)) <= 0) { + return FALSE; + } + + numUsed = numDevSections; + + if (numUsed > 0) { + + for (i = 0; i < numUsed; i++) { + ScrnInfoPtr pScrn = NULL; + int entityIndex = + xf86ClaimNoSlot(drv,DUMMY_CHIP,devSections[i],TRUE); + /* Allocate a ScrnInfoRec and claim the slot */ + if ((pScrn = xf86AllocateScreen(drv,0 ))) { + xf86AddEntityToScreen(pScrn,entityIndex); + pScrn->driverVersion = DUMMY_VERSION; + pScrn->driverName = DUMMY_DRIVER_NAME; + pScrn->name = DUMMY_NAME; + pScrn->Probe = DUMMYProbe; + pScrn->PreInit = DUMMYPreInit; + pScrn->ScreenInit = DUMMYScreenInit; + pScrn->SwitchMode = DUMMYSwitchMode; + pScrn->AdjustFrame = DUMMYAdjustFrame; + pScrn->EnterVT = DUMMYEnterVT; + pScrn->LeaveVT = DUMMYLeaveVT; + pScrn->FreeScreen = DUMMYFreeScreen; + pScrn->ValidMode = DUMMYValidMode; + + foundScreen = TRUE; + } + } + } + + free(devSections); + + return foundScreen; +} + +# define RETURN \ + { DUMMYFreeRec(pScrn);\ + return FALSE;\ + } + +/* Mandatory */ +Bool +DUMMYPreInit(ScrnInfoPtr pScrn, int flags) +{ + ClockRangePtr clockRanges; + int i; + DUMMYPtr dPtr; + int maxClock = 300000; + GDevPtr device = xf86GetEntityInfo(pScrn->entityList[0])->device; + + if (flags & PROBE_DETECT) + return TRUE; + + /* Allocate the DummyRec driverPrivate */ + if (!DUMMYGetRec(pScrn)) { + return FALSE; + } + + dPtr = DUMMYPTR(pScrn); + + pScrn->chipset = (char *)xf86TokenToString(DUMMYChipsets, + DUMMY_CHIP); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Chipset is a DUMMY\n"); + + pScrn->monitor = pScrn->confScreen->monitor; + + if (!xf86SetDepthBpp(pScrn, 0, 0, 0, Support24bppFb | Support32bppFb)) + return FALSE; + else { + /* Check that the returned depth is one we support */ + switch (pScrn->depth) { + case 8: + case 15: + case 16: + case 24: + case 30: + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by this driver\n", + pScrn->depth); + return FALSE; + } + } + + xf86PrintDepthBpp(pScrn); + if (pScrn->depth == 8) + pScrn->rgbBits = 8; + + /* Get the depth24 pixmap format */ + if (pScrn->depth == 24 && pix24bpp == 0) + pix24bpp = xf86GetBppFromDepth(pScrn, 24); + + /* + * This must happen after pScrn->display has been set because + * xf86SetWeight references it. + */ + if (pScrn->depth > 8) { + /* The defaults are OK for us */ + rgb zeros = {0, 0, 0}; + + if (!xf86SetWeight(pScrn, zeros, zeros)) { + return FALSE; + } else { + /* XXX check that weight returned is supported */ + ; + } + } + + if (!xf86SetDefaultVisual(pScrn, -1)) + return FALSE; + + if (pScrn->depth > 1) { + Gamma zeros = {0.0, 0.0, 0.0}; + + if (!xf86SetGamma(pScrn, zeros)) + return FALSE; + } + + xf86CollectOptions(pScrn, device->options); + /* Process the options */ + if (!(dPtr->Options = malloc(sizeof(DUMMYOptions)))) + return FALSE; + memcpy(dPtr->Options, DUMMYOptions, sizeof(DUMMYOptions)); + + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, dPtr->Options); + + xf86GetOptValBool(dPtr->Options, OPTION_SW_CURSOR,&dPtr->swCursor); + + if (device->videoRam != 0) { + pScrn->videoRam = device->videoRam; + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "VideoRAM: %d kByte\n", + pScrn->videoRam); + } else { + pScrn->videoRam = 4096; + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VideoRAM: %d kByte\n", + pScrn->videoRam); + } + + if (device->dacSpeeds[0] != 0) { + maxClock = device->dacSpeeds[0]; + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Max Clock: %d kHz\n", + maxClock); + } else { + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Max Clock: %d kHz\n", + maxClock); + } + + pScrn->progClock = TRUE; + /* + * Setup the ClockRanges, which describe what clock ranges are available, + * and what sort of modes they can be used for. + */ + clockRanges = (ClockRangePtr)xnfcalloc(sizeof(ClockRange), 1); + clockRanges->next = NULL; + clockRanges->ClockMulFactor = 1; + clockRanges->minClock = 11000; /* guessed §§§ */ + clockRanges->maxClock = maxClock; + clockRanges->clockIndex = -1; /* programmable */ + clockRanges->interlaceAllowed = TRUE; + clockRanges->doubleScanAllowed = TRUE; + + /* Subtract memory for HW cursor */ + + + { + int apertureSize = (pScrn->videoRam * 1024); + i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, + pScrn->display->modes, clockRanges, + NULL, 256, DUMMY_MAX_WIDTH, + (8 * pScrn->bitsPerPixel), + 128, DUMMY_MAX_HEIGHT, pScrn->display->virtualX, + pScrn->display->virtualY, apertureSize, + LOOKUP_BEST_REFRESH); + + if (i == -1) + RETURN; + } + + /* Prune the modes marked as invalid */ + xf86PruneDriverModes(pScrn); + + if (i == 0 || pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n"); + RETURN; + } + + /* + * Set the CRTC parameters for all of the modes based on the type + * of mode, and the chipset's interlace requirements. + * + * Calling this is required if the mode->Crtc* values are used by the + * driver and if the driver doesn't provide code to set them. They + * are not pre-initialised at all. + */ + xf86SetCrtcForModes(pScrn, 0); + + /* Set the current mode to the first in the list */ + pScrn->currentMode = pScrn->modes; + + /* Print the list of modes being used */ + xf86PrintModes(pScrn); + + /* If monitor resolution is set on the command line, use it */ + xf86SetDpi(pScrn, 0, 0); + + if (xf86LoadSubModule(pScrn, "fb") == NULL) { + RETURN; + } + + if (!dPtr->swCursor) { + if (!xf86LoadSubModule(pScrn, "ramdac")) + RETURN; + } + + /* We have no contiguous physical fb in physical memory */ + pScrn->memPhysBase = 0; + pScrn->fbOffset = 0; + + return TRUE; +} +#undef RETURN + +/* Mandatory */ +static Bool +DUMMYEnterVT(VT_FUNC_ARGS_DECL) +{ + return TRUE; +} + +/* Mandatory */ +static void +DUMMYLeaveVT(VT_FUNC_ARGS_DECL) +{ +} + +static void +DUMMYLoadPalette( + ScrnInfoPtr pScrn, + int numColors, + int *indices, + LOCO *colors, + VisualPtr pVisual +){ + int i, index, shift, Gshift; + DUMMYPtr dPtr = DUMMYPTR(pScrn); + + switch(pScrn->depth) { + case 15: + shift = Gshift = 1; + break; + case 16: + shift = 0; + Gshift = 0; + break; + default: + shift = Gshift = 0; + break; + } + + for(i = 0; i < numColors; i++) { + index = indices[i]; + dPtr->colors[index].red = colors[index].red << shift; + dPtr->colors[index].green = colors[index].green << Gshift; + dPtr->colors[index].blue = colors[index].blue << shift; + } + +} + +static ScrnInfoPtr DUMMYScrn; /* static-globalize it */ + +/* Mandatory */ +static Bool +DUMMYScreenInit(SCREEN_INIT_ARGS_DECL) +{ + ScrnInfoPtr pScrn; + DUMMYPtr dPtr; + int ret; + VisualPtr visual; + void *pixels; + + /* + * we need to get the ScrnInfoRec for this screen, so let's allocate + * one first thing + */ + pScrn = xf86ScreenToScrn(pScreen); + dPtr = DUMMYPTR(pScrn); + DUMMYScrn = pScrn; + + + if (!(pixels = malloc(pScrn->videoRam * 1024))) + return FALSE; + + /* + * Reset visual list. + */ + miClearVisualTypes(); + + /* Setup the visuals we support. */ + + if (!miSetVisualTypes(pScrn->depth, + miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; + + if (!miSetPixmapDepths ()) return FALSE; + + /* + * Call the framebuffer layer's ScreenInit function, and fill in other + * pScreen fields. + */ + ret = fbScreenInit(pScreen, pixels, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, pScrn->bitsPerPixel); + if (!ret) + return FALSE; + + if (pScrn->depth > 8) { + /* Fixup RGB ordering */ + visual = pScreen->visuals + pScreen->numVisuals; + while (--visual >= pScreen->visuals) { + if ((visual->class | DynamicClass) == DirectColor) { + visual->offsetRed = pScrn->offset.red; + visual->offsetGreen = pScrn->offset.green; + visual->offsetBlue = pScrn->offset.blue; + visual->redMask = pScrn->mask.red; + visual->greenMask = pScrn->mask.green; + visual->blueMask = pScrn->mask.blue; + } + } + } + + /* must be after RGB ordering fixed */ + fbPictureInit(pScreen, 0, 0); + + xf86SetBlackWhitePixels(pScreen); + + if (dPtr->swCursor) + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using Software Cursor.\n"); + + { + + + BoxRec AvailFBArea; + int lines = pScrn->videoRam * 1024 / + (pScrn->displayWidth * (pScrn->bitsPerPixel >> 3)); + AvailFBArea.x1 = 0; + AvailFBArea.y1 = 0; + AvailFBArea.x2 = pScrn->displayWidth; + AvailFBArea.y2 = lines; + xf86InitFBManager(pScreen, &AvailFBArea); + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + "Using %i scanlines of offscreen memory \n" + , lines - pScrn->virtualY); + } + + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + + /* Initialise cursor functions */ + miDCInitialize (pScreen, xf86GetPointerScreenFuncs()); + + + if (!dPtr->swCursor) { + /* HW cursor functions */ + if (!DUMMYCursorInit(pScreen)) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Hardware cursor initialization failed\n"); + return FALSE; + } + } + + /* Initialise default colourmap */ + if(!miCreateDefColormap(pScreen)) + return FALSE; + + if (!xf86HandleColormaps(pScreen, 1024, pScrn->rgbBits, + DUMMYLoadPalette, NULL, + CMAP_PALETTED_TRUECOLOR + | CMAP_RELOAD_ON_MODE_SWITCH)) + return FALSE; + + pScreen->SaveScreen = DUMMYSaveScreen; + + + /* Wrap the current CloseScreen function */ + dPtr->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = DUMMYCloseScreen; + + /* Wrap the current CreateWindow function */ + dPtr->CreateWindow = pScreen->CreateWindow; + pScreen->CreateWindow = DUMMYCreateWindow; + + /* Report any unused options (only for the first generation) */ + if (serverGeneration == 1) { + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + } + + return TRUE; +} + +/* Mandatory */ +Bool +DUMMYSwitchMode(SWITCH_MODE_ARGS_DECL) +{ + return TRUE; +} + +/* Mandatory */ +void +DUMMYAdjustFrame(ADJUST_FRAME_ARGS_DECL) +{ +} + +/* Mandatory */ +static Bool +DUMMYCloseScreen(CLOSE_SCREEN_ARGS_DECL) +{ + ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); + DUMMYPtr dPtr = DUMMYPTR(pScrn); + + free(pScreen->GetScreenPixmap(pScreen)->devPrivate.ptr); + + if (dPtr->CursorInfo) + xf86DestroyCursorInfoRec(dPtr->CursorInfo); + + pScrn->vtSema = FALSE; + pScreen->CloseScreen = dPtr->CloseScreen; + return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS); +} + +/* Optional */ +static void +DUMMYFreeScreen(FREE_SCREEN_ARGS_DECL) +{ + SCRN_INFO_PTR(arg); + DUMMYFreeRec(pScrn); +} + +static Bool +DUMMYSaveScreen(ScreenPtr pScreen, int mode) +{ + return TRUE; +} + +/* Optional */ +static ModeStatus +DUMMYValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags) +{ + return(MODE_OK); +} + +Atom VFB_PROP = 0; +#define VFB_PROP_NAME "VFB_IDENT" + +static Bool +DUMMYCreateWindow(WindowPtr pWin) +{ + ScreenPtr pScreen = pWin->drawable.pScreen; + DUMMYPtr dPtr = DUMMYPTR(DUMMYScrn); + WindowPtr pWinRoot; + int ret; + + pScreen->CreateWindow = dPtr->CreateWindow; + ret = pScreen->CreateWindow(pWin); + dPtr->CreateWindow = pScreen->CreateWindow; + pScreen->CreateWindow = DUMMYCreateWindow; + + if(ret != TRUE) + return(ret); + + if(dPtr->prop == FALSE) { +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 8 + pWinRoot = WindowTable[DUMMYScrn->pScreen->myNum]; +#else + pWinRoot = DUMMYScrn->pScreen->root; +#endif + if (! ValidAtom(VFB_PROP)) + VFB_PROP = MakeAtom(VFB_PROP_NAME, strlen(VFB_PROP_NAME), 1); + + ret = dixChangeWindowProperty(serverClient, pWinRoot, VFB_PROP, + XA_STRING, 8, PropModeReplace, + (int)4, (pointer)"TRUE", FALSE); + if( ret != Success) + ErrorF("Could not set VFB root window property"); + dPtr->prop = TRUE; + + return TRUE; + } + return TRUE; +} + +#ifndef HW_SKIP_CONSOLE +#define HW_SKIP_CONSOLE 4 +#endif + +static Bool +dummyDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr) +{ + CARD32 *flag; + + switch (op) { + case GET_REQUIRED_HW_INTERFACES: + flag = (CARD32*)ptr; + (*flag) = HW_SKIP_CONSOLE; + return TRUE; + default: + return FALSE; + } +} -- 2.11.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel