diff options
author | Corentin Chary <corentin.chary@gmail.com> | 2011-05-18 10:03:12 +0200 |
---|---|---|
committer | Corentin Chary <corentin.chary@gmail.com> | 2011-05-18 10:03:12 +0200 |
commit | 83411363e6fc3fc8066feed47bd418c0e9e0080d (patch) | |
tree | ecd301bc40910d5cb7a168c0191dce41b743e67e |
Initial commit: xterm works
Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
-rw-r--r-- | .gitignore | 78 | ||||
-rw-r--r-- | COPYING | 2 | ||||
-rw-r--r-- | Makefile.am | 29 | ||||
-rw-r--r-- | README | 20 | ||||
-rwxr-xr-x | autogen.sh | 12 | ||||
-rw-r--r-- | configure.ac | 76 | ||||
-rw-r--r-- | src/Makefile.am | 36 | ||||
-rw-r--r-- | src/wlshm.c | 756 | ||||
-rw-r--r-- | src/wlshm.h | 55 |
9 files changed, 1064 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..537929d --- /dev/null +++ b/.gitignore @@ -0,0 +1,78 @@ +# +# X.Org module default exclusion patterns +# The next section if for module specific patterns +# +# Do not edit the following section +# GNU Build System (Autotools) +aclocal.m4 +autom4te.cache/ +autoscan.log +ChangeLog +compile +config.guess +config.h +config.h.in +config.log +config-ml.in +config.py +config.status +config.status.lineno +config.sub +configure +configure.scan +depcomp +.deps/ +INSTALL +install-sh +.libs/ +libtool +libtool.m4 +ltmain.sh +lt~obsolete.m4 +ltoptions.m4 +ltsugar.m4 +ltversion.m4 +Makefile +Makefile.in +mdate-sh +missing +mkinstalldirs +*.pc +py-compile +stamp-h? +symlink-tree +texinfo.tex +ylwrap + +# Do not edit the following section +# Edit Compile Debug Document Distribute +*~ +*.[0-9] +*.[0-9]x +*.bak +*.bin +core +*.dll +*.exe +*-ISO*.bdf +*-JIS*.bdf +*-KOI8*.bdf +*.kld +*.ko +*.ko.cmd +*.lai +*.l[oa] +*.[oa] +*.obj +*.patch +*.so +*.pcf.gz +*.pdb +*.tar.bz2 +*.tar.gz +# +# Add & Override patterns for xf86-video-dummy +# +# Edit the following section as needed +# For example, !report.pc overrides *.pc. See 'man gitignore' +# @@ -0,0 +1,2 @@ +Copyright 2002, SuSE Linux AG, Author: Egbert Eich +Copyright 2011, commonIT, Author: Corentin Chary diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..af06d52 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,29 @@ +# 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 @@ -0,0 +1,20 @@ +xf86-video-wlshm - virtual/offscreen frame buffer driver for the Xorg X server + +Please submit bugs & patches to the Xorg bugzilla: + + https://bugs.freedesktop.org/enter_bug.cgi?product=wayland + +All questions regarding this software should be directed at the +Wayland mailing list: + + http://lists.freedesktop.org/mailman/listinfo/wayland-devel + +The master development code repository can be found at: + + git://anongit.freedesktop.org/git/xorg/driver/xf86-video-wlshm + + http://cgit.freedesktop.org/xorg/driver/xf86-video-wlshm + +For more information on the git code manager, see: + + http://wiki.x.org/wiki/GitPage diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..904cd67 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,12 @@ +#! /bin/sh + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir + +autoreconf -v --install || exit 1 +cd $ORIGDIR || exit $? + +$srcdir/configure --enable-maintainer-mode "$@" diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..163b9d2 --- /dev/null +++ b/configure.ac @@ -0,0 +1,76 @@ +# 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-wlshm], + [0.3.4], + [https://bugs.freedesktop.org/enter_bug.cgi?product=wayland], + [xf86-video-wlshm]) +AC_CONFIG_SRCDIR([Makefile.am]) +AC_CONFIG_HEADERS([config.h]) +AC_CONFIG_AUX_DIR(.) + +# Initialize Automake +AM_INIT_AUTOMAKE([foreign dist-bzip2]) +AM_MAINTAINER_MODE + +# 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) +XORG_DRIVER_CHECK_EXT(XV, videoproto) +XORG_DRIVER_CHECK_EXT(XFreeXDGA, xf86dgaproto) + +# Obtain compiler/linker options for the driver dependencies +PKG_CHECK_MODULES(XORG, [xorg-server >= 1.0.99.901] xproto fontsproto $REQUIRED_MODULES) + +# Checks for libraries. +PKG_CHECK_MODULES(WAYLAND, [wayland-client]) + + +DRIVER_NAME=wlshm +AC_SUBST([DRIVER_NAME]) + +AC_CONFIG_FILES([ + Makefile + src/Makefile +]) +AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..3d27981 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,36 @@ +# 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 wlshm 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) + +wlshm_drv_la_LTLIBRARIES = wlshm_drv.la +wlshm_drv_la_LDFLAGS = -module -avoid-version +wlshm_drv_ladir = @moduledir@/drivers + +wlshm_drv_la_SOURCES = \ + wlshm.c \ + wlshm.h diff --git a/src/wlshm.c b/src/wlshm.c new file mode 100644 index 0000000..ed3b0ce --- /dev/null +++ b/src/wlshm.c @@ -0,0 +1,756 @@ + +/* + * Copyright 2002, SuSE Linux AG, Author: Egbert Eich + * Copyright 2010, commonIT, Author: Corentin Chary + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* All drivers should typically include these */ +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86Modes.h" +#include "micmap.h" + +/* All drivers initialising the SW cursor need this */ +#include "mipointer.h" + +/* All drivers implementing backing store need this */ +#include "mibstore.h" + +/* All drivers using framebuffer need this */ +#include "xf86fbman.h" +#include "fb.h" +#include "picturestr.h" + +/* All drivers using hosted module need this */ +#include "hosted.h" +#include <xorg/xf86Priv.h> + +/* + * Driver data structures. + */ +#include "wlshm.h" + +#include <sys/mman.h> +#include <unistd.h> +#include <errno.h> + +/* These need to be checked */ +#include <X11/X.h> +#include <X11/Xproto.h> +#include "scrnintstr.h" +#include "servermd.h" + +#define WLSHM_VERSION 0001 +#define WLSHM_NAME "wlshm" +#define WLSHM_DRIVER_NAME "wlshm" + +#define WLSHM_MAJOR_VERSION PACKAGE_VERSION_MAJOR +#define WLSHM_MINOR_VERSION PACKAGE_VERSION_MINOR +#define WLSHM_PATCHLEVEL PACKAGE_VERSION_PATCHLEVEL + +static DevPrivateKeyRec wlshm_pixmap_private_key; + +static Bool +wlshm_get_device(ScrnInfoPtr pScrn) +{ + /* + * Allocate a wlshm_device, 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(struct wlshm_device), 1); + + if (pScrn->driverPrivate == NULL) + return FALSE; + + return TRUE; +} + +static void +wlshm_free_device(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate == NULL) + return; + free(pScrn->driverPrivate); + pScrn->driverPrivate = NULL; +} + +static void +wlshm_save(ScrnInfoPtr pScrn) +{ +} + +static void +wlshm_restore(ScrnInfoPtr pScrn, Bool restoreText) +{ +} + +static Bool +wlshm_save_screen(ScreenPtr pScreen, int mode) +{ + return TRUE; +} + +static Bool +wlshm_mode_init(ScrnInfoPtr pScrn, DisplayModePtr mode) +{ + wlshm_restore(pScrn, FALSE); + + return TRUE; +} + +static Bool +wlshm_enter_vt(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + + /* Should we re-save the text mode on each VT enter? */ + if(!wlshm_mode_init(pScrn, pScrn->currentMode)) + return FALSE; + + return TRUE; +} + +static void +wlshm_leave_vt(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + wlshm_restore(pScrn, TRUE); +} + +static Bool +wlshm_switch_mode(int scrnIndex, DisplayModePtr mode, int flags) +{ + return wlshm_mode_init(xf86Screens[scrnIndex], mode); +} + +static void +wlshm_adjust_frame(int scrnIndex, int x, int y, int flags) +{ +} + +static void +wlshm_flush_callback(CallbackListPtr *list, + pointer user_data, pointer call_data) +{ + struct wlshm_device *wlshm = user_data; + + if (wlshm->hosted_screen) + hosted_screen_post_damage(wlshm->hosted_screen); +} + +static Bool +wlshm_close_screen(int scrnIndex, ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + struct wlshm_device *wlshm = wlshm_scrninfo_priv(pScrn); + + DeleteCallback(&FlushCallback, wlshm_flush_callback, wlshm); + + if(pScrn->vtSema){ + wlshm_restore(pScrn, TRUE); + free(wlshm->fb); + } + + pScrn->vtSema = FALSE; + pScreen->CloseScreen = wlshm->CloseScreen; + return (*pScreen->CloseScreen)(scrnIndex, pScreen); +} + +static void +wlshm_free_screen(int scrnIndex, int flags) +{ + wlshm_free_device(xf86Screens[scrnIndex]); +} + +static ModeStatus +wlshm_valid_mode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags) +{ + return(MODE_OK); +} + +static void +wlshm_free_window_pixmap(WindowPtr pWindow) +{ + ScreenPtr pScreen = pWindow->drawable.pScreen; + struct wlshm_device *wlshm = wlshm_screen_priv(pScreen); + struct wlshm_pixmap *d; + PixmapPtr pixmap; + + pixmap = pScreen->GetWindowPixmap(pWindow); + if (!pixmap) + return ; + + d = dixLookupPrivate(&pixmap->devPrivates, &wlshm_pixmap_private_key); + if (!d) + return ; + + dixSetPrivate(&pixmap->devPrivates, &wlshm_pixmap_private_key, NULL); + + pixmap->devPrivate.ptr = d->orig; + memcpy(d->orig, d->data, d->bytes); + munmap(d->data, d->bytes); + free(d); +} + +static Bool +wlshm_unrealize_window(WindowPtr pWindow) +{ + ScreenPtr pScreen = pWindow->drawable.pScreen; + struct wlshm_device *wlshm = wlshm_screen_priv(pScreen); + Bool ret; + + wlshm_free_window_pixmap(pWindow); + + pScreen->UnrealizeWindow = wlshm->UnrealizeWindow; + ret = (*pScreen->UnrealizeWindow)(pWindow); + wlshm->UnrealizeWindow = pScreen->UnrealizeWindow; + pScreen->UnrealizeWindow = wlshm_unrealize_window; + + return ret; +} + +static void +wlshm_set_window_pixmap(WindowPtr pWindow, PixmapPtr pPixmap) +{ + ScreenPtr pScreen = pWindow->drawable.pScreen; + struct wlshm_device *wlshm = wlshm_screen_priv(pScreen); + + wlshm_free_window_pixmap(pWindow); + + pScreen->SetWindowPixmap = wlshm->SetWindowPixmap; + (*pScreen->SetWindowPixmap)(pWindow, pPixmap); + wlshm->SetWindowPixmap = pScreen->SetWindowPixmap; + pScreen->SetWindowPixmap = wlshm_set_window_pixmap; + + /* hosted will call create_window_buffer later */ +} + +static Bool +wlshm_create_window(WindowPtr pWin) +{ + ScreenPtr pScreen = pWin->drawable.pScreen; + struct wlshm_device *wlshm = wlshm_screen_priv(pScreen); + int ret; + + fprintf(stderr, "create window!\n"); + pScreen->CreateWindow = wlshm->CreateWindow; + ret = pScreen->CreateWindow(pWin); + wlshm->CreateWindow = pScreen->CreateWindow; + pScreen->CreateWindow = wlshm_create_window; + + PixmapPtr pixmap = fbCreatePixmap(pScreen, + pWin->drawable.width, + pWin->drawable.height, + pWin->drawable.depth, 0); + _fbSetWindowPixmap(pWin, pixmap); + + return ret; +} + +static Bool +wlshm_screen_init(int scrnIndex, ScreenPtr pScreen, int argc, char **argv) +{ + ScrnInfoPtr pScrn; + struct wlshm_device *wlshm; + int ret; + VisualPtr visual; + + if (!dixRegisterPrivateKey(&wlshm_pixmap_private_key, PRIVATE_PIXMAP, 0)) + return BadAlloc; + /* + * we need to get the ScrnInfoRec for this screen, so let's allocate + * one first thing + */ + pScrn = xf86Screens[pScreen->myNum]; + wlshm = wlshm_screen_priv(pScreen); + + /* + * next we save the current state and setup the first mode + */ + wlshm_save(pScrn); + + if (!wlshm_mode_init(pScrn,pScrn->currentMode)) + 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; + + wlshm->fb = malloc(pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel); + + if (!wlshm) + return FALSE; + + /* + * Call the framebuffer layer's ScreenInit function, and fill in other + * pScreen fields. + */ + ret = fbScreenInit(pScreen, wlshm->fb, + 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); + + { + BoxRec AvailFBArea; + + AvailFBArea.x1 = 0; + AvailFBArea.y1 = 0; + AvailFBArea.x2 = pScrn->displayWidth; + AvailFBArea.y2 = pScrn->virtualY; + + xf86InitFBManager(pScreen, &AvailFBArea); + } + + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + xf86SetSilkenMouse(pScreen); + + /* Initialise cursor functions */ + miDCInitialize (pScreen, xf86GetPointerScreenFuncs()); + + /* FIXME: colourmap */ + miCreateDefColormap(pScreen); + + pScreen->SaveScreen = wlshm_save_screen; + + /* Wrap the current CloseScreen function */ + wlshm->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = wlshm_close_screen; + + /* Wrap the current CreateWindow function */ + wlshm->CreateWindow = pScreen->CreateWindow; + pScreen->CreateWindow = wlshm_create_window; + + /* Wrap the current UnrealizeWindow function */ + wlshm->UnrealizeWindow = pScreen->UnrealizeWindow; + pScreen->UnrealizeWindow = wlshm_unrealize_window; + + /* Wrap the current SetWindowPixmap function */ + wlshm->SetWindowPixmap = pScreen->SetWindowPixmap; + pScreen->SetWindowPixmap = wlshm_set_window_pixmap; + + AddCallback(&FlushCallback, wlshm_flush_callback, wlshm); + + /* Report any unused options (only for the first generation) */ + if (serverGeneration == 1) { + xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options); + } + + miScreenDevPrivateInit(pScreen, pScreen->width, wlshm->fb); + + if (wlshm->hosted_screen) + hosted_screen_init(wlshm->hosted_screen, pScreen); + + return TRUE; +} + +static int +wlshm_create_window_buffer(struct hosted_window *hosted_window, + PixmapPtr pixmap) +{ + ScreenPtr pScreen = pixmap->drawable.pScreen; + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + char filename[] = "/tmp/wayland-shm-XXXXXX"; + int ret = BadAlloc; + struct wlshm_pixmap *d; + + fprintf(stderr, "create window buffer\n"); + d = calloc(sizeof (struct wlshm_pixmap), 1); + if (!d) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "can't alloc wlshm pixmap: %s\n", + strerror(errno)); + goto exit; + } + d->fd = -1; + d->data = MAP_FAILED; + + d->fd = mkstemp(filename); + if (d->fd < 0) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "open %s failed: %s\n", + filename, strerror(errno)); + goto exit; + } + + d->bytes = pixmap->drawable.width * pixmap->drawable.height + * pixmap->drawable.bitsPerPixel / 8; + + if (ftruncate(d->fd, d->bytes) < 0) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "ftruncate failed: %s\n", + strerror(errno)); + goto exit; + } + + d->data = mmap(NULL, d->bytes, PROT_READ | PROT_WRITE, MAP_SHARED, d->fd, 0); + unlink(filename); + + if (d->data == MAP_FAILED) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "mmap failed: %s\n", + strerror(errno)); + goto exit; + } + + ret = hosted_create_window_buffer_shm(hosted_window, pixmap, d->fd); + if (ret != Success) { + goto exit; + } + + d->orig = pixmap->devPrivate.ptr; + pixmap->devPrivate.ptr = d->data; + + memcpy(d->data, d->orig, d->bytes); + fprintf(stderr, "create window buffer %p %p %d\n", d->data, d->orig, d->bytes); + dixSetPrivate(&pixmap->devPrivates, &wlshm_pixmap_private_key, d); + + return ret; +exit: + if (d) { + if (d->fd != -1) + close(d->fd); + if (d->data != MAP_FAILED) + munmap(d->data, d->bytes); + free(d); + } + + return ret; +} + +static struct hosted_driver hosted_driver = { + .version = 2, + .create_window_buffer = wlshm_create_window_buffer +}; + +static const OptionInfoRec wlshm_options[] = { + { -1, NULL, OPTV_NONE, {0}, FALSE } +}; + +static Bool +wlshm_pre_init(ScrnInfoPtr pScrn, int flags) +{ + struct wlshm_device *wlshm; + int i; + GDevPtr device = xf86GetEntityInfo(pScrn->entityList[0])->device; + int flags24; + + if (flags & PROBE_DETECT) + return TRUE; + + if (!xorgHosted) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "You must run Xorg with -hosted parameter\n"); + return FALSE; + } + + /* Allocate the wlshm_device driverPrivate */ + if (!wlshm_get_device(pScrn)) { + return FALSE; + } + + wlshm = wlshm_scrninfo_priv(pScrn); + + pScrn->chipset = "wlshm"; + pScrn->monitor = pScrn->confScreen->monitor; + + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Initializing Wayland SHM driver\n"); + + flags24 = Support32bppFb | SupportConvert24to32 | PreferConvert24to32; + if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24)) { + return FALSE; + } else { + /* Check that the returned depth is one we support */ + switch (pScrn->depth) { + case 24: + case 30: + case 32: + break ; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by this driver\n", + pScrn->depth); + return FALSE; + } + } + + xf86PrintDepthBpp(pScrn); + + /* + * 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 (!(wlshm->options = malloc(sizeof(wlshm_options)))) + return FALSE; + + memcpy(wlshm->options, wlshm_options, sizeof(wlshm_options)); + + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, wlshm->options); + + if (xf86LoadSubModule(pScrn, "hosted") == NULL) { + goto error; + } + + wlshm->hosted_screen = hosted_screen_pre_init(pScrn, 0, &hosted_driver); + if (!wlshm->hosted_screen) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Failed to initialize hosted.\n"); + goto error; + } + + /* Subtract memory for HW cursor */ + xf86ValidateModesSize(pScrn, pScrn->monitor->Modes, + pScrn->display->virtualX, + pScrn->display->virtualY, + 0); + + /* Prune the modes marked as invalid */ + xf86PruneDriverModes(pScrn); + + if (pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes found\n"); + goto error; + } + + /* + * 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) { + goto error; + } + + /* We have no contiguous physical fb in physical memory */ + pScrn->memPhysBase = 0; + pScrn->fbOffset = 0; + + return TRUE; + +error: + wlshm_free_device(pScrn); + return FALSE; +} + +/* Mandatory */ +static Bool +wlshm_probe(DriverPtr drv, int flags) +{ + Bool found = FALSE; + int count; + GDevPtr *sections; + int i; + + if (flags & PROBE_DETECT) + return FALSE; + /* + * Find the config file Device sections that match this + * driver, and return if there are none. + */ + count = xf86MatchDevice(WLSHM_DRIVER_NAME, §ions); + + if (count <= 0) { + return FALSE; + } + + for (i = 0; i < count; i++) { + int entityIndex = xf86ClaimNoSlot(drv, 0, sections[i], TRUE); + ScrnInfoPtr pScrn = xf86AllocateScreen(drv, 0); + + if (!pScrn) + continue ; + + xf86AddEntityToScreen(pScrn, entityIndex); + pScrn->driverVersion = WLSHM_VERSION; + pScrn->driverName = WLSHM_DRIVER_NAME; + pScrn->name = WLSHM_NAME; + pScrn->Probe = wlshm_probe; + pScrn->PreInit = wlshm_pre_init; + pScrn->ScreenInit = wlshm_screen_init; + pScrn->SwitchMode = wlshm_switch_mode; + pScrn->AdjustFrame = wlshm_adjust_frame; + pScrn->EnterVT = wlshm_enter_vt; + pScrn->LeaveVT = wlshm_leave_vt; + pScrn->FreeScreen = wlshm_free_screen; + pScrn->ValidMode = wlshm_valid_mode; + + found = TRUE; + } + + return found; +} + +static const OptionInfoRec * +wlshm_available_options(int chipid, int busid) +{ + return wlshm_options; +} + +#ifndef HW_SKIP_CONSOLE +#define HW_SKIP_CONSOLE 4 +#endif + +static Bool +wlshm_driver_func(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; + } +} + +/* + * 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 wlshm = { + WLSHM_VERSION, + WLSHM_DRIVER_NAME, + NULL, + wlshm_probe, + wlshm_available_options, + NULL, + 0, + wlshm_driver_func +}; + +#ifdef XFree86LOADER + +static XF86ModuleVersionInfo wlshm_vers_rec = +{ + "wlshm", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XORG_VERSION_CURRENT, + WLSHM_MAJOR_VERSION, WLSHM_MINOR_VERSION, WLSHM_PATCHLEVEL, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0,0,0,0} +}; + + +static pointer +wlshm_setup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool initialized = FALSE; + + if (!initialized) { + initialized = TRUE; + xf86AddDriver(&wlshm, 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; + } +} + +static MODULESETUPPROTO(wlshm_setup); + +/* + * This is the module init data. + * Its name has to be the driver name followed by ModuleData + */ +_X_EXPORT XF86ModuleData wlshmModuleData = { + &wlshm_vers_rec, + wlshm_setup, + NULL +}; + +#endif /* XFree86LOADER */ diff --git a/src/wlshm.h b/src/wlshm.h new file mode 100644 index 0000000..620235c --- /dev/null +++ b/src/wlshm.h @@ -0,0 +1,55 @@ +#ifndef _XF86_VIDEO_WAYLAND_SHM_H_ +#define _XF86_VIDEO_WAYLAND_SHM_H_ + +/* All drivers should typically include these */ +#include "xf86.h" +#include "xf86_OSproc.h" + +#include "xf86Cursor.h" + +#include "xf86xv.h" +#include <X11/extensions/Xv.h> +#include <string.h> + +#include "hosted.h" + +/* globals */ +struct wlshm_device +{ + DGAModePtr dga_modes; + int num_dga_modes; + Bool dga_active; + int dga_viewport_status; + + /* options */ + OptionInfoPtr options; + + /* proc pointer */ + CloseScreenProcPtr CloseScreen; + CreateWindowProcPtr CreateWindow; + UnrealizeWindowProcPtr UnrealizeWindow; + SetWindowPixmapProcPtr SetWindowPixmap; + + pointer* fb; + + struct hosted_screen *hosted_screen; +}; + +struct wlshm_pixmap { + int fd; + void *orig; + void *data; + size_t bytes; +}; + +static inline struct wlshm_device *wlshm_scrninfo_priv(ScrnInfoPtr pScrn) +{ + return ((struct wlshm_device *)((pScrn)->driverPrivate)); +} + +static inline struct wlshm_device *wlshm_screen_priv(ScreenPtr pScreen) +{ + return wlshm_scrninfo_priv(xf86Screens[pScreen->myNum]); +} + +#endif |