diff --git a/.appveyor.yml b/.appveyor.yml index 9c5ad95af..75e0542ed 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -72,7 +72,7 @@ cache: - '%CYGWIN_ROOT%\home\%USERNAME%\.ccache' build_script: - SET PATH=%CYGWIN_ROOT%/bin -- '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; meson setup --prefix=/usr -Dxv=false -Dxf86bigfont=true -Dxephyr=true -Dxvfb=true -Dhal=false -Dudev=false build"' +- '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; meson setup --prefix=/usr -Dxv=false -Dxf86bigfont=true -Dxvfb=true -Dhal=false -Dudev=false build"' - '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; meson configure build"' - '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ninja -C build"' - '%CYGWIN_ROOT%/bin/bash -lc "cd $APPVEYOR_BUILD_FOLDER; ccache -s"' diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dd54692c1..d927f8c22 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -62,7 +62,7 @@ debian-buster: meson: extends: .common-build-and-test script: - - meson -Dc_args="-fno-common" -Dprefix=/usr -Dxephyr=true -Dwerror=true $MESON_EXTRA_OPTIONS build/ + - meson -Dc_args="-fno-common" -Dprefix=/usr -Dwerror=true $MESON_EXTRA_OPTIONS build/ - ninja -j${FDO_CI_CONCURRENT:-4} -C build/ dist - PIGLIT_DIR=/root/piglit XTEST_DIR=/root/xts ninja -j${FDO_CI_CONCURRENT:-4} -C build/ test - .gitlab-ci/manpages-check diff --git a/hw/kdrive/Xkdrive.man b/hw/kdrive/Xkdrive.man deleted file mode 100644 index 4a5ee21c4..000000000 --- a/hw/kdrive/Xkdrive.man +++ /dev/null @@ -1,50 +0,0 @@ -.\" $RCSId: xc/programs/Xserver/hw/kdrive/Xkdrive.man,v 1.3 2001/01/24 00:06:10 dawes Exp $ -.\" -.TH Xkdrive 1 @vendorversion@ -.SH NAME -Xkdrive \- tiny X server -.SH SYNOPSIS -.B Xfbdev -.RI [ :display ] -.RI [ option ...] -.SH DESCRIPTION -.B Xkdrive -is a family of X servers designed to be particularly small. This -manual page describes the common functionality of the -.B Xkdrive -servers; for information on a specific X server, please refer to the -relevant manual page. -.SH OPTIONS -In addition to the standard options accepted by all X servers (see -Xserver(1)), all the -.B Xkdrive -servers accept the following options: -.TP 8 -.B -dumb -disable hardware acceleration. -.TP 8 -.B -origin \fIX\fP,\fIY\fP -Locates the next screen in the Xinerama virtual screen. -.TP 8 -.B -screen \fIwidth\fBx\fIheight\fR[\fBx\fIdepth\fR[\fBx\fIfreq\fR]]\fR[\fB@\fIrotation\fR]\fB -use a screen of the specified \fIwidth\fP, \fIheight\fP, screen \fIdepth\fP, \fIfrequency\fP, and \fIrotation\fP (0, 90, 180 and 270 are legal values). -.TP 8 -.B -softCursor -disable the hardware cursor. -.TP 8 -.B -videoTest -start the server, pause momentarily, and exit. -.TP 8 -.B -zaphod -disable switching screens by moving the pointer across a screen boundary. -.TP 8 -.B -2button -enable emulation of a middle mouse button by chording. -.TP 8 -.B -3button -disable emulation of a middle mouse button by chording. -.SH SEE ALSO -X(@miscmansuffix@), Xserver(1), xdm(1), xinit(1), Xvesa(1), Xfbdev(1). -.SH AUTHORS -The Xkdrive common core was written by Keith Packard, -and is based on the Sample Implementation of X. diff --git a/hw/kdrive/ephyr/.gitignore b/hw/kdrive/ephyr/.gitignore deleted file mode 100644 index 4962d1ef0..000000000 --- a/hw/kdrive/ephyr/.gitignore +++ /dev/null @@ -1 +0,0 @@ -Xephyr diff --git a/hw/kdrive/ephyr/README b/hw/kdrive/ephyr/README deleted file mode 100644 index 5019fbb5f..000000000 --- a/hw/kdrive/ephyr/README +++ /dev/null @@ -1,71 +0,0 @@ -Xephyr README -============= - - -What Is It ? -============ - -Xephyr is a a kdrive server that outputs to a window on a pre-existing -'host' X display. Think Xnest but with support for modern extensions -like composite, damage and randr. - -Unlike Xnest which is an X proxy, i.e. limited to the -capabilities of the host X server, Xephyr is a real X server which -uses the host X server window as "framebuffer" via fast SHM XImages. - -It also has support for 'visually' debugging what the server is -painting. - - -How To Use -========== - -You probably want to run like; - -Xephyr :1 -ac -screen 800x600 & - -Then set DISPLAY=:1 and run whatever X apps you like. - -Use 'xrandr' to change to orientation/size. - -There is a '-parent' switch which works just like Xnest's ( for use -with things like matchbox-nest - http://matchbox.handhelds.org ). - -There is also a '-host-cursor' switch to set 'cursor acceleration' - -The host's cursor is reused. This is only really there to aid -debugging by avoiding server paints for the cursor. Performance -improvement is negligible. - -Send a SIGUSR1 to the server ( eg kill -USR1 `pidof Xephyr` ) to -toggle the debugging mode. In this mode red rectangles are painted to -screen areas getting painted before painting the actual content. The -delay between this can be altered by setting a XEPHYR_PAUSE env var to -a value in microseconds. - - -Caveats -======= - - - Depth is limited to being the same as the host. - *Update* As of 8/11/2004. Xephyr can now do 8bpp & 16bpp - on 24bpp host. - - - Rotated displays are currently updated via full blits. This - is slower than a normal oprientated display. Debug mode will - therefore not be of much use rotated. - - - The '-host-cursor' cursor is static in its appearance. - - - The build gets a warning about 'nanosleep'. I think the various '-D' - build flags are causing this. I haven't figured as yet how to work - around it. It doesn't appear to break anything however. - - - Keyboard handling is basic but works. - - - Mouse button 5 probably won't work. - - - - - -Matthew Allum 2004 diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c deleted file mode 100644 index c503ad6a6..000000000 --- a/hw/kdrive/ephyr/ephyr.c +++ /dev/null @@ -1,1392 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2004 Nokia - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Nokia not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Nokia makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include -#include - -#include "ephyr.h" - -#include "inputstr.h" -#include "scrnintstr.h" -#include "ephyrlog.h" - -#ifdef GLAMOR -#include "glamor.h" -#endif -#include "ephyr_glamor_glx.h" -#include "glx_extinit.h" -#include "xkbsrv.h" - -extern Bool ephyr_glamor; - -KdKeyboardInfo *ephyrKbd; -KdPointerInfo *ephyrMouse; -Bool ephyrNoDRI = FALSE; -Bool ephyrNoXV = FALSE; - -static int mouseState = 0; -static Rotation ephyrRandr = RR_Rotate_0; - -typedef struct _EphyrInputPrivate { - Bool enabled; -} EphyrKbdPrivate, EphyrPointerPrivate; - -Bool EphyrWantGrayScale = 0; -Bool EphyrWantResize = 0; -Bool EphyrWantNoHostGrab = 0; - -Bool -ephyrInitialize(KdCardInfo * card, EphyrPriv * priv) -{ - OsSignal(SIGUSR1, hostx_handle_signal); - - priv->base = 0; - priv->bytes_per_line = 0; - return TRUE; -} - -Bool -ephyrCardInit(KdCardInfo * card) -{ - EphyrPriv *priv; - - priv = (EphyrPriv *) malloc(sizeof(EphyrPriv)); - if (!priv) - return FALSE; - - if (!ephyrInitialize(card, priv)) { - free(priv); - return FALSE; - } - card->driver = priv; - - return TRUE; -} - -Bool -ephyrScreenInitialize(KdScreenInfo *screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - int x = 0, y = 0; - int width = 640, height = 480; - CARD32 redMask, greenMask, blueMask; - - if (hostx_want_screen_geometry(screen, &width, &height, &x, &y) - || !screen->width || !screen->height) { - screen->width = width; - screen->height = height; - screen->x = x; - screen->y = y; - } - - if (EphyrWantGrayScale) - screen->fb.depth = 8; - - if (screen->fb.depth && screen->fb.depth != hostx_get_depth()) { - if (screen->fb.depth < hostx_get_depth() - && (screen->fb.depth == 24 || screen->fb.depth == 16 - || screen->fb.depth == 8)) { - scrpriv->server_depth = screen->fb.depth; - } - else - ErrorF - ("\nXephyr: requested screen depth not supported, setting to match hosts.\n"); - } - - screen->fb.depth = hostx_get_server_depth(screen); - screen->rate = 72; - - if (screen->fb.depth <= 8) { - if (EphyrWantGrayScale) - screen->fb.visuals = ((1 << StaticGray) | (1 << GrayScale)); - else - screen->fb.visuals = ((1 << StaticGray) | - (1 << GrayScale) | - (1 << StaticColor) | - (1 << PseudoColor) | - (1 << TrueColor) | (1 << DirectColor)); - - screen->fb.redMask = 0x00; - screen->fb.greenMask = 0x00; - screen->fb.blueMask = 0x00; - screen->fb.depth = 8; - screen->fb.bitsPerPixel = 8; - } - else { - screen->fb.visuals = (1 << TrueColor); - - if (screen->fb.depth <= 15) { - screen->fb.depth = 15; - screen->fb.bitsPerPixel = 16; - } - else if (screen->fb.depth <= 16) { - screen->fb.depth = 16; - screen->fb.bitsPerPixel = 16; - } - else if (screen->fb.depth <= 24) { - screen->fb.depth = 24; - screen->fb.bitsPerPixel = 32; - } - else if (screen->fb.depth <= 30) { - screen->fb.depth = 30; - screen->fb.bitsPerPixel = 32; - } - else { - ErrorF("\nXephyr: Unsupported screen depth %d\n", screen->fb.depth); - return FALSE; - } - - hostx_get_visual_masks(screen, &redMask, &greenMask, &blueMask); - - screen->fb.redMask = (Pixel) redMask; - screen->fb.greenMask = (Pixel) greenMask; - screen->fb.blueMask = (Pixel) blueMask; - - } - - scrpriv->randr = screen->randr; - - return ephyrMapFramebuffer(screen); -} - -void * -ephyrWindowLinear(ScreenPtr pScreen, - CARD32 row, - CARD32 offset, int mode, CARD32 *size, void *closure) -{ - KdScreenPriv(pScreen); - EphyrPriv *priv = pScreenPriv->card->driver; - - if (!pScreenPriv->enabled) - return 0; - - *size = priv->bytes_per_line; - return priv->base + row * priv->bytes_per_line + offset; -} - -/** - * Figure out display buffer size. If fakexa is enabled, allocate a larger - * buffer so that fakexa has space to put offscreen pixmaps. - */ -int -ephyrBufferHeight(KdScreenInfo * screen) -{ - int buffer_height; - - if (ephyrFuncs.initAccel == NULL) - buffer_height = screen->height; - else - buffer_height = 3 * screen->height; - return buffer_height; -} - -Bool -ephyrMapFramebuffer(KdScreenInfo * screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - EphyrPriv *priv = screen->card->driver; - KdPointerMatrix m; - int buffer_height; - - EPHYR_LOG("screen->width: %d, screen->height: %d index=%d", - screen->width, screen->height, screen->mynum); - - /* - * Use the rotation last applied to ourselves (in the Xephyr case the fb - * coordinate system moves independently of the pointer coordinate system). - */ - KdComputePointerMatrix(&m, ephyrRandr, screen->width, screen->height); - KdSetPointerMatrix(&m); - - buffer_height = ephyrBufferHeight(screen); - - priv->base = - hostx_screen_init(screen, screen->x, screen->y, - screen->width, screen->height, buffer_height, - &priv->bytes_per_line, &screen->fb.bitsPerPixel); - - if ((scrpriv->randr & RR_Rotate_0) && !(scrpriv->randr & RR_Reflect_All)) { - scrpriv->shadow = FALSE; - - screen->fb.byteStride = priv->bytes_per_line; - screen->fb.pixelStride = screen->width; - screen->fb.frameBuffer = (CARD8 *) (priv->base); - } - else { - /* Rotated/Reflected so we need to use shadow fb */ - scrpriv->shadow = TRUE; - - EPHYR_LOG("allocing shadow"); - - KdShadowFbAlloc(screen, - scrpriv->randr & (RR_Rotate_90 | RR_Rotate_270)); - } - - return TRUE; -} - -void -ephyrSetScreenSizes(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv->randr & (RR_Rotate_0 | RR_Rotate_180)) { - pScreen->width = screen->width; - pScreen->height = screen->height; - pScreen->mmWidth = screen->width_mm; - pScreen->mmHeight = screen->height_mm; - } - else { - pScreen->width = screen->height; - pScreen->height = screen->width; - pScreen->mmWidth = screen->height_mm; - pScreen->mmHeight = screen->width_mm; - } -} - -Bool -ephyrUnmapFramebuffer(KdScreenInfo * screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv->shadow) - KdShadowFbFree(screen); - - /* Note, priv->base will get freed when XImage recreated */ - - return TRUE; -} - -void -ephyrShadowUpdate(ScreenPtr pScreen, shadowBufPtr pBuf) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - - EPHYR_LOG("slow paint"); - - /* FIXME: Slow Rotated/Reflected updates could be much - * much faster efficiently updating via transforming - * pBuf->pDamage regions - */ - shadowUpdateRotatePacked(pScreen, pBuf); - hostx_paint_rect(screen, 0, 0, 0, 0, screen->width, screen->height); -} - -static void -ephyrInternalDamageRedisplay(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - RegionPtr pRegion; - - if (!scrpriv || !scrpriv->pDamage) - return; - - pRegion = DamageRegion(scrpriv->pDamage); - - if (RegionNotEmpty(pRegion)) { - int nbox; - BoxPtr pbox; - - if (ephyr_glamor) { - ephyr_glamor_damage_redisplay(scrpriv->glamor, pRegion); - } else { - nbox = RegionNumRects(pRegion); - pbox = RegionRects(pRegion); - - while (nbox--) { - hostx_paint_rect(screen, - pbox->x1, pbox->y1, - pbox->x1, pbox->y1, - pbox->x2 - pbox->x1, pbox->y2 - pbox->y1); - pbox++; - } - } - DamageEmpty(scrpriv->pDamage); - } -} - -static void -ephyrXcbProcessEvents(Bool queued_only); - -static Bool -ephyrEventWorkProc(ClientPtr client, void *closure) -{ - ephyrXcbProcessEvents(TRUE); - return TRUE; -} - -static void -ephyrScreenBlockHandler(ScreenPtr pScreen, void *timeout) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - - pScreen->BlockHandler = scrpriv->BlockHandler; - (*pScreen->BlockHandler)(pScreen, timeout); - scrpriv->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = ephyrScreenBlockHandler; - - if (scrpriv->pDamage) - ephyrInternalDamageRedisplay(pScreen); - - if (hostx_has_queued_event()) { - if (!QueueWorkProc(ephyrEventWorkProc, NULL, NULL)) - FatalError("cannot queue event processing in ephyr block handler"); - AdjustWaitForDelay(timeout, 0); - } -} - -Bool -ephyrSetInternalDamage(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - PixmapPtr pPixmap = NULL; - - scrpriv->pDamage = DamageCreate((DamageReportFunc) 0, - (DamageDestroyFunc) 0, - DamageReportNone, TRUE, pScreen, pScreen); - - pPixmap = (*pScreen->GetScreenPixmap) (pScreen); - - DamageRegister(&pPixmap->drawable, scrpriv->pDamage); - - return TRUE; -} - -void -ephyrUnsetInternalDamage(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - - DamageDestroy(scrpriv->pDamage); - scrpriv->pDamage = NULL; -} - -#ifdef RANDR -Bool -ephyrRandRGetInfo(ScreenPtr pScreen, Rotation * rotations) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - RRScreenSizePtr pSize; - Rotation randr; - int n = 0; - - struct { - int width, height; - } sizes[] = { - {1600, 1200}, - {1400, 1050}, - {1280, 960}, - {1280, 1024}, - {1152, 864}, - {1024, 768}, - {832, 624}, - {800, 600}, - {720, 400}, - {480, 640}, - {640, 480}, - {640, 400}, - {320, 240}, - {240, 320}, - {160, 160}, - {0, 0} - }; - - EPHYR_LOG("mark"); - - *rotations = RR_Rotate_All | RR_Reflect_All; - - if (!hostx_want_preexisting_window(screen) - && !hostx_want_fullscreen()) { /* only if no -parent switch */ - while (sizes[n].width != 0 && sizes[n].height != 0) { - RRRegisterSize(pScreen, - sizes[n].width, - sizes[n].height, - (sizes[n].width * screen->width_mm) / screen->width, - (sizes[n].height * screen->height_mm) / - screen->height); - n++; - } - } - - pSize = RRRegisterSize(pScreen, - screen->width, - screen->height, screen->width_mm, screen->height_mm); - - randr = KdSubRotation(scrpriv->randr, screen->randr); - - RRSetCurrentConfig(pScreen, randr, 0, pSize); - - return TRUE; -} - -Bool -ephyrRandRSetConfig(ScreenPtr pScreen, - Rotation randr, int rate, RRScreenSizePtr pSize) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - Bool wasEnabled = pScreenPriv->enabled; - EphyrScrPriv oldscr; - int oldwidth, oldheight, oldmmwidth, oldmmheight; - Bool oldshadow; - int newwidth, newheight; - - if (screen->randr & (RR_Rotate_0 | RR_Rotate_180)) { - newwidth = pSize->width; - newheight = pSize->height; - } - else { - newwidth = pSize->height; - newheight = pSize->width; - } - - if (wasEnabled) - KdDisableScreen(pScreen); - - oldscr = *scrpriv; - - oldwidth = screen->width; - oldheight = screen->height; - oldmmwidth = pScreen->mmWidth; - oldmmheight = pScreen->mmHeight; - oldshadow = scrpriv->shadow; - - /* - * Set new configuration - */ - - /* - * We need to store the rotation value for pointer coords transformation; - * though initially the pointer and fb rotation are identical, when we map - * the fb, the screen will be reinitialized and return into an unrotated - * state (presumably the HW is taking care of the rotation of the fb), but the - * pointer still needs to be transformed. - */ - ephyrRandr = KdAddRotation(screen->randr, randr); - scrpriv->randr = ephyrRandr; - - ephyrUnmapFramebuffer(screen); - - screen->width = newwidth; - screen->height = newheight; - - scrpriv->win_width = screen->width; - scrpriv->win_height = screen->height; -#ifdef GLAMOR - ephyr_glamor_set_window_size(scrpriv->glamor, - scrpriv->win_width, - scrpriv->win_height); -#endif - - if (!ephyrMapFramebuffer(screen)) - goto bail4; - - /* FIXME below should go in own call */ - - if (oldshadow) - KdShadowUnset(screen->pScreen); - else - ephyrUnsetInternalDamage(screen->pScreen); - - ephyrSetScreenSizes(screen->pScreen); - - if (scrpriv->shadow) { - if (!KdShadowSet(screen->pScreen, - scrpriv->randr, ephyrShadowUpdate, ephyrWindowLinear)) - goto bail4; - } - else { -#ifdef GLAMOR - if (ephyr_glamor) - ephyr_glamor_create_screen_resources(pScreen); -#endif - /* Without shadow fb ( non rotated ) we need - * to use damage to efficiently update display - * via signal regions what to copy from 'fb'. - */ - if (!ephyrSetInternalDamage(screen->pScreen)) - goto bail4; - } - - /* - * Set frame buffer mapping - */ - (*pScreen->ModifyPixmapHeader) (fbGetScreenPixmap(pScreen), - pScreen->width, - pScreen->height, - screen->fb.depth, - screen->fb.bitsPerPixel, - screen->fb.byteStride, - screen->fb.frameBuffer); - - /* set the subpixel order */ - - KdSetSubpixelOrder(pScreen, scrpriv->randr); - - if (wasEnabled) - KdEnableScreen(pScreen); - - RRScreenSizeNotify(pScreen); - - return TRUE; - - bail4: - EPHYR_LOG("bailed"); - - ephyrUnmapFramebuffer(screen); - *scrpriv = oldscr; - (void) ephyrMapFramebuffer(screen); - - pScreen->width = oldwidth; - pScreen->height = oldheight; - pScreen->mmWidth = oldmmwidth; - pScreen->mmHeight = oldmmheight; - - if (wasEnabled) - KdEnableScreen(pScreen); - return FALSE; -} - -Bool -ephyrRandRInit(ScreenPtr pScreen) -{ - rrScrPrivPtr pScrPriv; - - if (!RRScreenInit(pScreen)) - return FALSE; - - pScrPriv = rrGetScrPriv(pScreen); - pScrPriv->rrGetInfo = ephyrRandRGetInfo; - pScrPriv->rrSetConfig = ephyrRandRSetConfig; - return TRUE; -} - -static Bool -ephyrResizeScreen (ScreenPtr pScreen, - int newwidth, - int newheight) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - RRScreenSize size = {0}; - Bool ret; - int t; - - if (screen->randr & (RR_Rotate_90|RR_Rotate_270)) { - t = newwidth; - newwidth = newheight; - newheight = t; - } - - if (newwidth == screen->width && newheight == screen->height) { - return FALSE; - } - - size.width = newwidth; - size.height = newheight; - - hostx_size_set_from_configure(TRUE); - ret = ephyrRandRSetConfig (pScreen, screen->randr, 0, &size); - hostx_size_set_from_configure(FALSE); - if (ret) { - RROutputPtr output; - - output = RRFirstOutput(pScreen); - if (!output) - return FALSE; - RROutputSetModes(output, NULL, 0, 0); - } - - return ret; -} -#endif - -Bool -ephyrCreateColormap(ColormapPtr pmap) -{ - return fbInitializeColormap(pmap); -} - -Bool -ephyrInitScreen(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - - EPHYR_LOG("pScreen->myNum:%d\n", pScreen->myNum); - hostx_set_screen_number(screen, pScreen->myNum); - if (EphyrWantNoHostGrab) { - hostx_set_win_title(screen, "xephyr"); - } else { - hostx_set_win_title(screen, "(ctrl+shift grabs mouse and keyboard)"); - } - pScreen->CreateColormap = ephyrCreateColormap; - -#ifdef XV - if (!ephyrNoXV) { - if (ephyr_glamor) - ephyr_glamor_xv_init(pScreen); - else if (!ephyrInitVideo(pScreen)) { - EPHYR_LOG_ERROR("failed to initialize xvideo\n"); - } - else { - EPHYR_LOG("initialized xvideo okay\n"); - } - } -#endif /*XV*/ - - return TRUE; -} - - -Bool -ephyrFinishInitScreen(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - - /* FIXME: Calling this even if not using shadow. - * Seems harmless enough. But may be safer elsewhere. - */ - if (!shadowSetup(pScreen)) - return FALSE; - -#ifdef RANDR - if (!ephyrRandRInit(pScreen)) - return FALSE; -#endif - - scrpriv->BlockHandler = pScreen->BlockHandler; - pScreen->BlockHandler = ephyrScreenBlockHandler; - - return TRUE; -} - -/** - * Called by kdrive after calling down the - * pScreen->CreateScreenResources() chain, this gives us a chance to - * make any pixmaps after the screen and all extensions have been - * initialized. - */ -Bool -ephyrCreateResources(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - - EPHYR_LOG("mark pScreen=%p mynum=%d shadow=%d", - pScreen, pScreen->myNum, scrpriv->shadow); - - if (scrpriv->shadow) - return KdShadowSet(pScreen, - scrpriv->randr, - ephyrShadowUpdate, ephyrWindowLinear); - else { -#ifdef GLAMOR - if (ephyr_glamor) { - if (!ephyr_glamor_create_screen_resources(pScreen)) - return FALSE; - } -#endif - return ephyrSetInternalDamage(pScreen); - } -} - -void -ephyrScreenFini(KdScreenInfo * screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv->shadow) { - KdShadowFbFree(screen); - } - scrpriv->BlockHandler = NULL; -} - -void -ephyrCloseScreen(ScreenPtr pScreen) -{ - ephyrUnsetInternalDamage(pScreen); -} - -/* - * Port of Mark McLoughlin's Xnest fix for focus in + modifier bug. - * See https://bugs.freedesktop.org/show_bug.cgi?id=3030 - */ -void -ephyrUpdateModifierState(unsigned int state) -{ - - DeviceIntPtr pDev = inputInfo.keyboard; - KeyClassPtr keyc = pDev->key; - int i; - CARD8 mask; - int xkb_state; - - if (!pDev) - return; - - xkb_state = XkbStateFieldFromRec(&pDev->key->xkbInfo->state); - state = state & 0xff; - - if (xkb_state == state) - return; - - for (i = 0, mask = 1; i < 8; i++, mask <<= 1) { - int key; - - /* Modifier is down, but shouldn't be */ - if ((xkb_state & mask) && !(state & mask)) { - int count = keyc->modifierKeyCount[i]; - - for (key = 0; key < MAP_LENGTH; key++) - if (keyc->xkbInfo->desc->map->modmap[key] & mask) { - if (mask == XCB_MOD_MASK_LOCK) { - KdEnqueueKeyboardEvent(ephyrKbd, key, FALSE); - KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); - } - else if (key_is_down(pDev, key, KEY_PROCESSED)) - KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); - - if (--count == 0) - break; - } - } - - /* Modifier should be down, but isn't */ - if (!(xkb_state & mask) && (state & mask)) - for (key = 0; key < MAP_LENGTH; key++) - if (keyc->xkbInfo->desc->map->modmap[key] & mask) { - KdEnqueueKeyboardEvent(ephyrKbd, key, FALSE); - if (mask == XCB_MOD_MASK_LOCK) - KdEnqueueKeyboardEvent(ephyrKbd, key, TRUE); - break; - } - } -} - -static Bool -ephyrCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y) -{ - return FALSE; -} - -static void -ephyrCrossScreen(ScreenPtr pScreen, Bool entering) -{ -} - -ScreenPtr ephyrCursorScreen; /* screen containing the cursor */ - -static void -ephyrWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) -{ - input_lock(); - ephyrCursorScreen = pScreen; - miPointerWarpCursor(inputInfo.pointer, pScreen, x, y); - - input_unlock(); -} - -miPointerScreenFuncRec ephyrPointerScreenFuncs = { - ephyrCursorOffScreen, - ephyrCrossScreen, - ephyrWarpCursor, -}; - -static KdScreenInfo * -screen_from_window(Window w) -{ - int i = 0; - - for (i = 0; i < screenInfo.numScreens; i++) { - ScreenPtr pScreen = screenInfo.screens[i]; - KdPrivScreenPtr kdscrpriv = KdGetScreenPriv(pScreen); - KdScreenInfo *screen = kdscrpriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv->win == w - || scrpriv->peer_win == w - || scrpriv->win_pre_existing == w) { - return screen; - } - } - - return NULL; -} - -static void -ephyrProcessErrorEvent(xcb_generic_event_t *xev) -{ - xcb_generic_error_t *e = (xcb_generic_error_t *)xev; - - FatalError("X11 error\n" - "Error code: %hhu\n" - "Sequence number: %hu\n" - "Major code: %hhu\tMinor code: %hu\n" - "Error value: %u\n", - e->error_code, - e->sequence, - e->major_code, e->minor_code, - e->resource_id); -} - -static void -ephyrProcessExpose(xcb_generic_event_t *xev) -{ - xcb_expose_event_t *expose = (xcb_expose_event_t *)xev; - KdScreenInfo *screen = screen_from_window(expose->window); - EphyrScrPriv *scrpriv = screen->driver; - - /* Wait for the last expose event in a series of cliprects - * to actually paint our screen. - */ - if (expose->count != 0) - return; - - if (scrpriv) { - hostx_paint_rect(scrpriv->screen, 0, 0, 0, 0, - scrpriv->win_width, - scrpriv->win_height); - } else { - EPHYR_LOG_ERROR("failed to get host screen\n"); - } -} - -static void -ephyrProcessMouseMotion(xcb_generic_event_t *xev) -{ - xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)xev; - KdScreenInfo *screen = screen_from_window(motion->event); - - if (!ephyrMouse || - !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) { - EPHYR_LOG("skipping mouse motion:%d\n", screen->pScreen->myNum); - return; - } - - if (ephyrCursorScreen != screen->pScreen) { - EPHYR_LOG("warping mouse cursor. " - "cur_screen:%d, motion_screen:%d\n", - ephyrCursorScreen->myNum, screen->pScreen->myNum); - ephyrWarpCursor(inputInfo.pointer, screen->pScreen, - motion->event_x, motion->event_y); - } - else { - int x = 0, y = 0; - - EPHYR_LOG("enqueuing mouse motion:%d\n", screen->pScreen->myNum); - x = motion->event_x; - y = motion->event_y; - EPHYR_LOG("initial (x,y):(%d,%d)\n", x, y); - - /* convert coords into desktop-wide coordinates. - * fill_pointer_events will convert that back to - * per-screen coordinates where needed */ - x += screen->pScreen->x; - y += screen->pScreen->y; - - KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_POINTER_DESKTOP, x, y, 0); - } -} - -static void -ephyrProcessButtonPress(xcb_generic_event_t *xev) -{ - xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev; - - if (!ephyrMouse || - !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) { - EPHYR_LOG("skipping mouse press:%d\n", screen_from_window(button->event)->pScreen->myNum); - return; - } - - ephyrUpdateModifierState(button->state); - /* This is a bit hacky. will break for button 5 ( defined as 0x10 ) - * Check KD_BUTTON defines in kdrive.h - */ - mouseState |= 1 << (button->detail - 1); - - EPHYR_LOG("enqueuing mouse press:%d\n", screen_from_window(button->event)->pScreen->myNum); - KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0); -} - -static void -ephyrProcessButtonRelease(xcb_generic_event_t *xev) -{ - xcb_button_press_event_t *button = (xcb_button_press_event_t *)xev; - - if (!ephyrMouse || - !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) { - return; - } - - ephyrUpdateModifierState(button->state); - mouseState &= ~(1 << (button->detail - 1)); - - EPHYR_LOG("enqueuing mouse release:%d\n", screen_from_window(button->event)->pScreen->myNum); - KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0); -} - -/* Xephyr wants ctrl+shift to grab the window, but that conflicts with - ctrl+alt+shift key combos. Remember the modifier state on key presses and - releases, if mod1 is pressed, we need ctrl, shift and mod1 released - before we allow a shift-ctrl grab activation. - - note: a key event contains the mask _before_ the current key takes - effect, so mod1_was_down will be reset on the first key press after all - three were released, not on the last release. That'd require some more - effort. - */ -static int -ephyrUpdateGrabModifierState(int state) -{ - static int mod1_was_down = 0; - - if ((state & (XCB_MOD_MASK_CONTROL|XCB_MOD_MASK_SHIFT|XCB_MOD_MASK_1)) == 0) - mod1_was_down = 0; - else if (state & XCB_MOD_MASK_1) - mod1_was_down = 1; - - return mod1_was_down; -} - -static void -ephyrProcessKeyPress(xcb_generic_event_t *xev) -{ - xcb_key_press_event_t *key = (xcb_key_press_event_t *)xev; - - if (!ephyrKbd || - !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled) { - return; - } - - ephyrUpdateGrabModifierState(key->state); - ephyrUpdateModifierState(key->state); - KdEnqueueKeyboardEvent(ephyrKbd, key->detail, FALSE); -} - -static void -ephyrProcessKeyRelease(xcb_generic_event_t *xev) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_key_release_event_t *key = (xcb_key_release_event_t *)xev; - static xcb_key_symbols_t *keysyms; - static int grabbed_screen = -1; - int mod1_down = ephyrUpdateGrabModifierState(key->state); - - if (!keysyms) - keysyms = xcb_key_symbols_alloc(conn); - - if (!EphyrWantNoHostGrab && - (((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L - || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R) - && (key->state & XCB_MOD_MASK_CONTROL)) || - ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Control_L - || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Control_R) - && (key->state & XCB_MOD_MASK_SHIFT)))) { - KdScreenInfo *screen = screen_from_window(key->event); - EphyrScrPriv *scrpriv = screen->driver; - - if (grabbed_screen != -1) { - xcb_ungrab_keyboard(conn, XCB_TIME_CURRENT_TIME); - xcb_ungrab_pointer(conn, XCB_TIME_CURRENT_TIME); - grabbed_screen = -1; - hostx_set_win_title(screen, - "(ctrl+shift grabs mouse and keyboard)"); - } - else if (!mod1_down) { - /* Attempt grab */ - xcb_grab_keyboard_cookie_t kbgrabc = - xcb_grab_keyboard(conn, - TRUE, - scrpriv->win, - XCB_TIME_CURRENT_TIME, - XCB_GRAB_MODE_ASYNC, - XCB_GRAB_MODE_ASYNC); - xcb_grab_keyboard_reply_t *kbgrabr; - xcb_grab_pointer_cookie_t pgrabc = - xcb_grab_pointer(conn, - TRUE, - scrpriv->win, - 0, - XCB_GRAB_MODE_ASYNC, - XCB_GRAB_MODE_ASYNC, - scrpriv->win, - XCB_NONE, - XCB_TIME_CURRENT_TIME); - xcb_grab_pointer_reply_t *pgrabr; - kbgrabr = xcb_grab_keyboard_reply(conn, kbgrabc, NULL); - if (!kbgrabr || kbgrabr->status != XCB_GRAB_STATUS_SUCCESS) { - xcb_discard_reply(conn, pgrabc.sequence); - xcb_ungrab_pointer(conn, XCB_TIME_CURRENT_TIME); - } else { - pgrabr = xcb_grab_pointer_reply(conn, pgrabc, NULL); - if (!pgrabr || pgrabr->status != XCB_GRAB_STATUS_SUCCESS) - { - xcb_ungrab_keyboard(conn, - XCB_TIME_CURRENT_TIME); - } else { - grabbed_screen = scrpriv->mynum; - hostx_set_win_title - (screen, - "(ctrl+shift releases mouse and keyboard)"); - } - } - } - } - - if (!ephyrKbd || - !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled) { - return; - } - - /* Still send the release event even if above has happened server - * will get confused with just an up event. Maybe it would be - * better to just block shift+ctrls getting to kdrive all - * together. - */ - ephyrUpdateModifierState(key->state); - KdEnqueueKeyboardEvent(ephyrKbd, key->detail, TRUE); -} - -static void -ephyrProcessConfigureNotify(xcb_generic_event_t *xev) -{ - xcb_configure_notify_event_t *configure = - (xcb_configure_notify_event_t *)xev; - KdScreenInfo *screen = screen_from_window(configure->window); - EphyrScrPriv *scrpriv = screen->driver; - - if (!scrpriv || - (scrpriv->win_pre_existing == None && !EphyrWantResize)) { - return; - } - -#ifdef RANDR - ephyrResizeScreen(screen->pScreen, configure->width, configure->height); -#endif /* RANDR */ -} - -static void -ephyrXcbProcessEvents(Bool queued_only) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_generic_event_t *expose = NULL, *configure = NULL; - - while (TRUE) { - xcb_generic_event_t *xev = hostx_get_event(queued_only); - - if (!xev) { - /* If our XCB connection has died (for example, our window was - * closed), exit now. - */ - if (xcb_connection_has_error(conn)) { - CloseWellKnownConnections(); - OsCleanup(1); - exit(1); - } - - break; - } - - switch (xev->response_type & 0x7f) { - case 0: - ephyrProcessErrorEvent(xev); - break; - - case XCB_EXPOSE: - free(expose); - expose = xev; - xev = NULL; - break; - - case XCB_MOTION_NOTIFY: - ephyrProcessMouseMotion(xev); - break; - - case XCB_KEY_PRESS: - ephyrProcessKeyPress(xev); - break; - - case XCB_KEY_RELEASE: - ephyrProcessKeyRelease(xev); - break; - - case XCB_BUTTON_PRESS: - ephyrProcessButtonPress(xev); - break; - - case XCB_BUTTON_RELEASE: - ephyrProcessButtonRelease(xev); - break; - - case XCB_CONFIGURE_NOTIFY: - free(configure); - configure = xev; - xev = NULL; - break; - } - - if (xev) { - if (ephyr_glamor) - ephyr_glamor_process_event(xev); - - free(xev); - } - } - - if (configure) { - ephyrProcessConfigureNotify(configure); - free(configure); - } - - if (expose) { - ephyrProcessExpose(expose); - free(expose); - } -} - -static void -ephyrXcbNotify(int fd, int ready, void *data) -{ - ephyrXcbProcessEvents(FALSE); -} - -void -ephyrCardFini(KdCardInfo * card) -{ - EphyrPriv *priv = card->driver; - - free(priv); -} - -void -ephyrGetColors(ScreenPtr pScreen, int n, xColorItem * pdefs) -{ - /* XXX Not sure if this is right */ - - EPHYR_LOG("mark"); - - while (n--) { - pdefs->red = 0; - pdefs->green = 0; - pdefs->blue = 0; - pdefs++; - } - -} - -void -ephyrPutColors(ScreenPtr pScreen, int n, xColorItem * pdefs) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - int min, max, p; - - /* XXX Not sure if this is right */ - - min = 256; - max = 0; - - while (n--) { - p = pdefs->pixel; - if (p < min) - min = p; - if (p > max) - max = p; - - hostx_set_cmap_entry(pScreen, p, - pdefs->red >> 8, - pdefs->green >> 8, pdefs->blue >> 8); - pdefs++; - } - if (scrpriv->pDamage) { - BoxRec box; - RegionRec region; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - RegionInit(®ion, &box, 1); - DamageReportDamage(scrpriv->pDamage, ®ion); - RegionUninit(®ion); - } -} - -/* Mouse calls */ - -static Status -MouseInit(KdPointerInfo * pi) -{ - pi->driverPrivate = (EphyrPointerPrivate *) - calloc(sizeof(EphyrPointerPrivate), 1); - ((EphyrPointerPrivate *) pi->driverPrivate)->enabled = FALSE; - pi->nAxes = 3; - pi->nButtons = 32; - free(pi->name); - pi->name = strdup("Xephyr virtual mouse"); - - /* - * Must transform pointer coords since the pointer position - * relative to the Xephyr window is controlled by the host server and - * remains constant regardless of any rotation applied to the Xephyr screen. - */ - pi->transformCoordinates = TRUE; - - ephyrMouse = pi; - return Success; -} - -static Status -MouseEnable(KdPointerInfo * pi) -{ - ((EphyrPointerPrivate *) pi->driverPrivate)->enabled = TRUE; - SetNotifyFd(hostx_get_fd(), ephyrXcbNotify, X_NOTIFY_READ, NULL); - return Success; -} - -static void -MouseDisable(KdPointerInfo * pi) -{ - ((EphyrPointerPrivate *) pi->driverPrivate)->enabled = FALSE; - RemoveNotifyFd(hostx_get_fd()); - return; -} - -static void -MouseFini(KdPointerInfo * pi) -{ - free(pi->driverPrivate); - ephyrMouse = NULL; - return; -} - -KdPointerDriver EphyrMouseDriver = { - "ephyr", - MouseInit, - MouseEnable, - MouseDisable, - MouseFini, - NULL, -}; - -/* Keyboard */ - -static Status -EphyrKeyboardInit(KdKeyboardInfo * ki) -{ - KeySymsRec keySyms; - CARD8 modmap[MAP_LENGTH]; - XkbControlsRec controls; - - ki->driverPrivate = (EphyrKbdPrivate *) - calloc(sizeof(EphyrKbdPrivate), 1); - - if (hostx_load_keymap(&keySyms, modmap, &controls)) { - XkbApplyMappingChange(ki->dixdev, &keySyms, - keySyms.minKeyCode, - keySyms.maxKeyCode - keySyms.minKeyCode + 1, - modmap, serverClient); - XkbDDXChangeControls(ki->dixdev, &controls, &controls); - free(keySyms.map); - } - - ki->minScanCode = keySyms.minKeyCode; - ki->maxScanCode = keySyms.maxKeyCode; - - if (ki->name != NULL) { - free(ki->name); - } - - ki->name = strdup("Xephyr virtual keyboard"); - ephyrKbd = ki; - return Success; -} - -static Status -EphyrKeyboardEnable(KdKeyboardInfo * ki) -{ - ((EphyrKbdPrivate *) ki->driverPrivate)->enabled = TRUE; - - return Success; -} - -static void -EphyrKeyboardDisable(KdKeyboardInfo * ki) -{ - ((EphyrKbdPrivate *) ki->driverPrivate)->enabled = FALSE; -} - -static void -EphyrKeyboardFini(KdKeyboardInfo * ki) -{ - free(ki->driverPrivate); - ephyrKbd = NULL; - return; -} - -static void -EphyrKeyboardLeds(KdKeyboardInfo * ki, int leds) -{ -} - -static void -EphyrKeyboardBell(KdKeyboardInfo * ki, int volume, int frequency, int duration) -{ -} - -KdKeyboardDriver EphyrKeyboardDriver = { - "ephyr", - EphyrKeyboardInit, - EphyrKeyboardEnable, - EphyrKeyboardLeds, - EphyrKeyboardBell, - EphyrKeyboardDisable, - EphyrKeyboardFini, - NULL, -}; diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h deleted file mode 100644 index 587a48dc7..000000000 --- a/hw/kdrive/ephyr/ephyr.h +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2004 Nokia - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Nokia not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Nokia makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _EPHYR_H_ -#define _EPHYR_H_ -#include -#include -#include -#include - -#include "os.h" /* for OsSignal() */ -#include "kdrive.h" -#include "hostx.h" -#include "exa.h" - -#ifdef RANDR -#include "randrstr.h" -#endif - -#include "damage.h" - -typedef struct _ephyrPriv { - CARD8 *base; - int bytes_per_line; -} EphyrPriv; - -typedef struct _ephyrFakexaPriv { - ExaDriverPtr exa; - Bool is_synced; - - /* The following are arguments and other information from Prepare* calls - * which are stored for use in the inner calls. - */ - int op; - PicturePtr pSrcPicture, pMaskPicture, pDstPicture; - void *saved_ptrs[3]; - PixmapPtr pDst, pSrc, pMask; - GCPtr pGC; -} EphyrFakexaPriv; - -typedef struct _ephyrScrPriv { - /* ephyr server info */ - Rotation randr; - Bool shadow; - DamagePtr pDamage; - EphyrFakexaPriv *fakexa; - - /* Host X window info */ - xcb_window_t win; - xcb_window_t win_pre_existing; /* Set via -parent option like xnest */ - xcb_window_t peer_win; /* Used for GL; should be at most one */ - xcb_image_t *ximg; - Bool win_explicit_position; - int win_x, win_y; - int win_width, win_height; - int server_depth; - const char *output; /* Set via -output option */ - unsigned char *fb_data; /* only used when host bpp != server bpp */ - xcb_shm_segment_info_t shminfo; - size_t shmsize; - - KdScreenInfo *screen; - int mynum; /* Screen number */ - unsigned long cmap[256]; - - ScreenBlockHandlerProcPtr BlockHandler; - - /** - * Per-screen Xlib-using state for glamor (private to - * ephyr_glamor_glx.c) - */ - struct ephyr_glamor *glamor; -} EphyrScrPriv; - -extern KdCardFuncs ephyrFuncs; -extern KdKeyboardInfo *ephyrKbd; -extern KdPointerInfo *ephyrMouse; - -extern miPointerScreenFuncRec ephyrPointerScreenFuncs; - -Bool - ephyrInitialize(KdCardInfo * card, EphyrPriv * priv); - -Bool - ephyrCardInit(KdCardInfo * card); - -Bool -ephyrScreenInitialize(KdScreenInfo *screen); - -Bool - ephyrInitScreen(ScreenPtr pScreen); - -Bool - ephyrFinishInitScreen(ScreenPtr pScreen); - -Bool - ephyrCreateResources(ScreenPtr pScreen); - -void - ephyrPreserve(KdCardInfo * card); - -Bool - ephyrEnable(ScreenPtr pScreen); - -Bool - ephyrDPMS(ScreenPtr pScreen, int mode); - -void - ephyrDisable(ScreenPtr pScreen); - -void - ephyrRestore(KdCardInfo * card); - -void - ephyrScreenFini(KdScreenInfo * screen); - -void -ephyrCloseScreen(ScreenPtr pScreen); - -void - ephyrCardFini(KdCardInfo * card); - -void - ephyrGetColors(ScreenPtr pScreen, int n, xColorItem * pdefs); - -void - ephyrPutColors(ScreenPtr pScreen, int n, xColorItem * pdefs); - -Bool - ephyrMapFramebuffer(KdScreenInfo * screen); - -void *ephyrWindowLinear(ScreenPtr pScreen, - CARD32 row, - CARD32 offset, int mode, CARD32 *size, void *closure); - -void - ephyrSetScreenSizes(ScreenPtr pScreen); - -Bool - ephyrUnmapFramebuffer(KdScreenInfo * screen); - -void - ephyrUnsetInternalDamage(ScreenPtr pScreen); - -Bool - ephyrSetInternalDamage(ScreenPtr pScreen); - -Bool - ephyrCreateColormap(ColormapPtr pmap); - -#ifdef RANDR -Bool - ephyrRandRGetInfo(ScreenPtr pScreen, Rotation * rotations); - -Bool - -ephyrRandRSetConfig(ScreenPtr pScreen, - Rotation randr, int rate, RRScreenSizePtr pSize); -Bool - ephyrRandRInit(ScreenPtr pScreen); - -void - ephyrShadowUpdate(ScreenPtr pScreen, shadowBufPtr pBuf); - -#endif - -void - ephyrUpdateModifierState(unsigned int state); - -extern KdPointerDriver EphyrMouseDriver; - -extern KdKeyboardDriver EphyrKeyboardDriver; - -extern Bool ephyrCursorInit(ScreenPtr pScreen); - -extern int ephyrBufferHeight(KdScreenInfo * screen); - -/* ephyr_draw.c */ - -Bool - ephyrDrawInit(ScreenPtr pScreen); - -void - ephyrDrawEnable(ScreenPtr pScreen); - -void - ephyrDrawDisable(ScreenPtr pScreen); - -void - ephyrDrawFini(ScreenPtr pScreen); - -/* hostx.c glamor support */ -Bool ephyr_glamor_init(ScreenPtr pScreen); -Bool ephyr_glamor_create_screen_resources(ScreenPtr pScreen); -void ephyr_glamor_enable(ScreenPtr pScreen); -void ephyr_glamor_disable(ScreenPtr pScreen); -void ephyr_glamor_fini(ScreenPtr pScreen); -void ephyr_glamor_host_paint_rect(ScreenPtr pScreen); - -/*ephyvideo.c*/ - -Bool ephyrInitVideo(ScreenPtr pScreen); - -/* ephyr_glamor_xv.c */ -#ifdef GLAMOR -void ephyr_glamor_xv_init(ScreenPtr screen); -#else /* !GLAMOR */ -static inline void -ephyr_glamor_xv_init(ScreenPtr screen) -{ -} -#endif /* !GLAMOR */ - -#endif diff --git a/hw/kdrive/ephyr/ephyr_draw.c b/hw/kdrive/ephyr/ephyr_draw.c deleted file mode 100644 index 64e07a7d1..000000000 --- a/hw/kdrive/ephyr/ephyr_draw.c +++ /dev/null @@ -1,533 +0,0 @@ -/* - * Copyright © 2006 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Authors: - * Eric Anholt - * - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "ephyr.h" -#include "exa_priv.h" -#include "fbpict.h" - -#define EPHYR_TRACE_DRAW 0 - -#if EPHYR_TRACE_DRAW -#define TRACE_DRAW() ErrorF("%s\n", __FUNCTION__); -#else -#define TRACE_DRAW() do { } while (0) -#endif - -/* Use some oddball alignments, to expose issues in alignment handling in EXA. */ -#define EPHYR_OFFSET_ALIGN 24 -#define EPHYR_PITCH_ALIGN 24 - -#define EPHYR_OFFSCREEN_SIZE (16 * 1024 * 1024) -#define EPHYR_OFFSCREEN_BASE (1 * 1024 * 1024) - -/** - * Forces a real devPrivate.ptr for hidden pixmaps, so that we can call down to - * fb functions. - */ -static void -ephyrPreparePipelinedAccess(PixmapPtr pPix, int index) -{ - KdScreenPriv(pPix->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - assert(fakexa->saved_ptrs[index] == NULL); - fakexa->saved_ptrs[index] = pPix->devPrivate.ptr; - - if (pPix->devPrivate.ptr != NULL) - return; - - pPix->devPrivate.ptr = fakexa->exa->memoryBase + exaGetPixmapOffset(pPix); -} - -/** - * Restores the original devPrivate.ptr of the pixmap from before we messed with - * it. - */ -static void -ephyrFinishPipelinedAccess(PixmapPtr pPix, int index) -{ - KdScreenPriv(pPix->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - pPix->devPrivate.ptr = fakexa->saved_ptrs[index]; - fakexa->saved_ptrs[index] = NULL; -} - -/** - * Sets up a scratch GC for fbFill, and saves other parameters for the - * ephyrSolid implementation. - */ -static Bool -ephyrPrepareSolid(PixmapPtr pPix, int alu, Pixel pm, Pixel fg) -{ - ScreenPtr pScreen = pPix->drawable.pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - ChangeGCVal tmpval[3]; - - ephyrPreparePipelinedAccess(pPix, EXA_PREPARE_DEST); - - fakexa->pDst = pPix; - fakexa->pGC = GetScratchGC(pPix->drawable.depth, pScreen); - - tmpval[0].val = alu; - tmpval[1].val = pm; - tmpval[2].val = fg; - ChangeGC(NullClient, fakexa->pGC, GCFunction | GCPlaneMask | GCForeground, - tmpval); - - ValidateGC(&pPix->drawable, fakexa->pGC); - - TRACE_DRAW(); - - return TRUE; -} - -/** - * Does an fbFill of the rectangle to be drawn. - */ -static void -ephyrSolid(PixmapPtr pPix, int x1, int y1, int x2, int y2) -{ - ScreenPtr pScreen = pPix->drawable.pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - fbFill(&fakexa->pDst->drawable, fakexa->pGC, x1, y1, x2 - x1, y2 - y1); -} - -/** - * Cleans up the scratch GC created in ephyrPrepareSolid. - */ -static void -ephyrDoneSolid(PixmapPtr pPix) -{ - ScreenPtr pScreen = pPix->drawable.pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - FreeScratchGC(fakexa->pGC); - - ephyrFinishPipelinedAccess(pPix, EXA_PREPARE_DEST); -} - -/** - * Sets up a scratch GC for fbCopyArea, and saves other parameters for the - * ephyrCopy implementation. - */ -static Bool -ephyrPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, int alu, - Pixel pm) -{ - ScreenPtr pScreen = pDst->drawable.pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - ChangeGCVal tmpval[2]; - - ephyrPreparePipelinedAccess(pDst, EXA_PREPARE_DEST); - ephyrPreparePipelinedAccess(pSrc, EXA_PREPARE_SRC); - - fakexa->pSrc = pSrc; - fakexa->pDst = pDst; - fakexa->pGC = GetScratchGC(pDst->drawable.depth, pScreen); - - tmpval[0].val = alu; - tmpval[1].val = pm; - ChangeGC(NullClient, fakexa->pGC, GCFunction | GCPlaneMask, tmpval); - - ValidateGC(&pDst->drawable, fakexa->pGC); - - TRACE_DRAW(); - - return TRUE; -} - -/** - * Does an fbCopyArea to take care of the requested copy. - */ -static void -ephyrCopy(PixmapPtr pDst, int srcX, int srcY, int dstX, int dstY, int w, int h) -{ - ScreenPtr pScreen = pDst->drawable.pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - fbCopyArea(&fakexa->pSrc->drawable, &fakexa->pDst->drawable, fakexa->pGC, - srcX, srcY, w, h, dstX, dstY); -} - -/** - * Cleans up the scratch GC created in ephyrPrepareCopy. - */ -static void -ephyrDoneCopy(PixmapPtr pDst) -{ - ScreenPtr pScreen = pDst->drawable.pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - FreeScratchGC(fakexa->pGC); - - ephyrFinishPipelinedAccess(fakexa->pSrc, EXA_PREPARE_SRC); - ephyrFinishPipelinedAccess(fakexa->pDst, EXA_PREPARE_DEST); -} - -/** - * Reports that we can always accelerate the given operation. This may not be - * desirable from an EXA testing standpoint -- testing the fallback paths would - * be useful, too. - */ -static Bool -ephyrCheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture, - PicturePtr pDstPicture) -{ - /* Exercise the component alpha helper, so fail on this case like a normal - * driver - */ - if (pMaskPicture && pMaskPicture->componentAlpha && op == PictOpOver) - return FALSE; - - return TRUE; -} - -/** - * Saves off the parameters for ephyrComposite. - */ -static Bool -ephyrPrepareComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture, - PicturePtr pDstPicture, PixmapPtr pSrc, PixmapPtr pMask, - PixmapPtr pDst) -{ - KdScreenPriv(pDst->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - ephyrPreparePipelinedAccess(pDst, EXA_PREPARE_DEST); - if (pSrc != NULL) - ephyrPreparePipelinedAccess(pSrc, EXA_PREPARE_SRC); - if (pMask != NULL) - ephyrPreparePipelinedAccess(pMask, EXA_PREPARE_MASK); - - fakexa->op = op; - fakexa->pSrcPicture = pSrcPicture; - fakexa->pMaskPicture = pMaskPicture; - fakexa->pDstPicture = pDstPicture; - fakexa->pSrc = pSrc; - fakexa->pMask = pMask; - fakexa->pDst = pDst; - - TRACE_DRAW(); - - return TRUE; -} - -/** - * Does an fbComposite to complete the requested drawing operation. - */ -static void -ephyrComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, - int dstX, int dstY, int w, int h) -{ - KdScreenPriv(pDst->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - fbComposite(fakexa->op, fakexa->pSrcPicture, fakexa->pMaskPicture, - fakexa->pDstPicture, srcX, srcY, maskX, maskY, dstX, dstY, - w, h); -} - -static void -ephyrDoneComposite(PixmapPtr pDst) -{ - KdScreenPriv(pDst->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - if (fakexa->pMask != NULL) - ephyrFinishPipelinedAccess(fakexa->pMask, EXA_PREPARE_MASK); - if (fakexa->pSrc != NULL) - ephyrFinishPipelinedAccess(fakexa->pSrc, EXA_PREPARE_SRC); - ephyrFinishPipelinedAccess(fakexa->pDst, EXA_PREPARE_DEST); -} - -/** - * Does fake acceleration of DownloadFromScren using memcpy. - */ -static Bool -ephyrDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, char *dst, - int dst_pitch) -{ - KdScreenPriv(pSrc->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - unsigned char *src; - int src_pitch, cpp; - - if (pSrc->drawable.bitsPerPixel < 8) - return FALSE; - - ephyrPreparePipelinedAccess(pSrc, EXA_PREPARE_SRC); - - cpp = pSrc->drawable.bitsPerPixel / 8; - src_pitch = exaGetPixmapPitch(pSrc); - src = fakexa->exa->memoryBase + exaGetPixmapOffset(pSrc); - src += y * src_pitch + x * cpp; - - for (; h > 0; h--) { - memcpy(dst, src, w * cpp); - dst += dst_pitch; - src += src_pitch; - } - - exaMarkSync(pSrc->drawable.pScreen); - - ephyrFinishPipelinedAccess(pSrc, EXA_PREPARE_SRC); - - return TRUE; -} - -/** - * Does fake acceleration of UploadToScreen using memcpy. - */ -static Bool -ephyrUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, - int src_pitch) -{ - KdScreenPriv(pDst->drawable.pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - unsigned char *dst; - int dst_pitch, cpp; - - if (pDst->drawable.bitsPerPixel < 8) - return FALSE; - - ephyrPreparePipelinedAccess(pDst, EXA_PREPARE_DEST); - - cpp = pDst->drawable.bitsPerPixel / 8; - dst_pitch = exaGetPixmapPitch(pDst); - dst = fakexa->exa->memoryBase + exaGetPixmapOffset(pDst); - dst += y * dst_pitch + x * cpp; - - for (; h > 0; h--) { - memcpy(dst, src, w * cpp); - dst += dst_pitch; - src += src_pitch; - } - - exaMarkSync(pDst->drawable.pScreen); - - ephyrFinishPipelinedAccess(pDst, EXA_PREPARE_DEST); - - return TRUE; -} - -static Bool -ephyrPrepareAccess(PixmapPtr pPix, int index) -{ - /* Make sure we don't somehow end up with a pointer that is in framebuffer - * and hasn't been readied for us. - */ - assert(pPix->devPrivate.ptr != NULL); - - return TRUE; -} - -/** - * In fakexa, we currently only track whether we have synced to the latest - * "accelerated" drawing that has happened or not. It's not used for anything - * yet. - */ -static int -ephyrMarkSync(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - fakexa->is_synced = FALSE; - - return 0; -} - -/** - * Assumes that we're waiting on the latest marker. When EXA gets smarter and - * starts using markers in a fine-grained way (for example, waiting on drawing - * to required pixmaps to complete, rather than waiting for all drawing to - * complete), we'll want to make the ephyrMarkSync/ephyrWaitMarker - * implementation fine-grained as well. - */ -static void -ephyrWaitMarker(ScreenPtr pScreen, int marker) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrFakexaPriv *fakexa = scrpriv->fakexa; - - fakexa->is_synced = TRUE; -} - -/** - * This function initializes EXA to use the fake acceleration implementation - * which just falls through to software. The purpose is to have a reliable, - * correct driver with which to test changes to the EXA core. - */ -Bool -ephyrDrawInit(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; - EphyrPriv *priv = screen->card->driver; - EphyrFakexaPriv *fakexa; - Bool success; - - fakexa = calloc(1, sizeof(*fakexa)); - if (fakexa == NULL) - return FALSE; - - fakexa->exa = exaDriverAlloc(); - if (fakexa->exa == NULL) { - free(fakexa); - return FALSE; - } - - fakexa->exa->memoryBase = (CARD8 *) (priv->base); - fakexa->exa->memorySize = priv->bytes_per_line * ephyrBufferHeight(screen); - fakexa->exa->offScreenBase = priv->bytes_per_line * screen->height; - - /* Since we statically link against EXA, we shouldn't have to be smart about - * versioning. - */ - fakexa->exa->exa_major = 2; - fakexa->exa->exa_minor = 0; - - fakexa->exa->PrepareSolid = ephyrPrepareSolid; - fakexa->exa->Solid = ephyrSolid; - fakexa->exa->DoneSolid = ephyrDoneSolid; - - fakexa->exa->PrepareCopy = ephyrPrepareCopy; - fakexa->exa->Copy = ephyrCopy; - fakexa->exa->DoneCopy = ephyrDoneCopy; - - fakexa->exa->CheckComposite = ephyrCheckComposite; - fakexa->exa->PrepareComposite = ephyrPrepareComposite; - fakexa->exa->Composite = ephyrComposite; - fakexa->exa->DoneComposite = ephyrDoneComposite; - - fakexa->exa->DownloadFromScreen = ephyrDownloadFromScreen; - fakexa->exa->UploadToScreen = ephyrUploadToScreen; - - fakexa->exa->MarkSync = ephyrMarkSync; - fakexa->exa->WaitMarker = ephyrWaitMarker; - - fakexa->exa->PrepareAccess = ephyrPrepareAccess; - - fakexa->exa->pixmapOffsetAlign = EPHYR_OFFSET_ALIGN; - fakexa->exa->pixmapPitchAlign = EPHYR_PITCH_ALIGN; - - fakexa->exa->maxX = 1023; - fakexa->exa->maxY = 1023; - - fakexa->exa->flags = EXA_OFFSCREEN_PIXMAPS; - - success = exaDriverInit(pScreen, fakexa->exa); - if (success) { - ErrorF("Initialized fake EXA acceleration\n"); - scrpriv->fakexa = fakexa; - } - else { - ErrorF("Failed to initialize EXA\n"); - free(fakexa->exa); - free(fakexa); - } - - return success; -} - -void -ephyrDrawEnable(ScreenPtr pScreen) -{ -} - -void -ephyrDrawDisable(ScreenPtr pScreen) -{ -} - -void -ephyrDrawFini(ScreenPtr pScreen) -{ -} - -/** - * exaDDXDriverInit is required by the top-level EXA module, and is used by - * the xorg DDX to hook in its EnableDisableFB wrapper. We don't need it, since - * we won't be enabling/disabling the FB. - */ -void -exaDDXDriverInit(ScreenPtr pScreen) -{ - ExaScreenPriv(pScreen); - - pExaScr->migration = ExaMigrationSmart; - pExaScr->checkDirtyCorrectness = TRUE; -} diff --git a/hw/kdrive/ephyr/ephyr_glamor_glx.c b/hw/kdrive/ephyr/ephyr_glamor_glx.c deleted file mode 100644 index 40b80cbe7..000000000 --- a/hw/kdrive/ephyr/ephyr_glamor_glx.c +++ /dev/null @@ -1,429 +0,0 @@ -/* - * Copyright © 2013 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/** @file ephyr_glamor_glx.c - * - * Separate file for hiding Xlib and GLX-using parts of xephyr from - * the rest of the server-struct-aware build. - */ - -#include -#include -#include -#undef Xcalloc -#undef Xrealloc -#undef Xfree -#include -#include -#include -#include -#include "ephyr_glamor_glx.h" -#include "os.h" -#include - -/* until we need geometry shaders GL3.1 should suffice. */ -/* Xephyr has its own copy of this for build reasons */ -#define GLAMOR_GL_CORE_VER_MAJOR 3 -#define GLAMOR_GL_CORE_VER_MINOR 1 -/** @{ - * - * global state for Xephyr with glamor. - * - * Xephyr can render with multiple windows, but all the windows have - * to be on the same X connection and all have to have the same - * visual. - */ -static Display *dpy; -static XVisualInfo *visual_info; -static GLXFBConfig fb_config; -Bool ephyr_glamor_gles2; -Bool ephyr_glamor_skip_present; -/** @} */ - -/** - * Per-screen state for Xephyr with glamor. - */ -struct ephyr_glamor { - GLXContext ctx; - Window win; - GLXWindow glx_win; - - GLuint tex; - - GLuint texture_shader; - GLuint texture_shader_position_loc; - GLuint texture_shader_texcoord_loc; - - /* Size of the window that we're rendering to. */ - unsigned width, height; - - GLuint vao, vbo; -}; - -static GLint -ephyr_glamor_compile_glsl_prog(GLenum type, const char *source) -{ - GLint ok; - GLint prog; - - prog = glCreateShader(type); - glShaderSource(prog, 1, (const GLchar **) &source, NULL); - glCompileShader(prog); - glGetShaderiv(prog, GL_COMPILE_STATUS, &ok); - if (!ok) { - GLchar *info; - GLint size; - - glGetShaderiv(prog, GL_INFO_LOG_LENGTH, &size); - info = malloc(size); - if (info) { - glGetShaderInfoLog(prog, size, NULL, info); - ErrorF("Failed to compile %s: %s\n", - type == GL_FRAGMENT_SHADER ? "FS" : "VS", info); - ErrorF("Program source:\n%s", source); - free(info); - } - else - ErrorF("Failed to get shader compilation info.\n"); - FatalError("GLSL compile failure\n"); - } - - return prog; -} - -static GLuint -ephyr_glamor_build_glsl_prog(GLuint vs, GLuint fs) -{ - GLint ok; - GLuint prog; - - prog = glCreateProgram(); - glAttachShader(prog, vs); - glAttachShader(prog, fs); - - glLinkProgram(prog); - glGetProgramiv(prog, GL_LINK_STATUS, &ok); - if (!ok) { - GLchar *info; - GLint size; - - glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size); - info = malloc(size); - - glGetProgramInfoLog(prog, size, NULL, info); - ErrorF("Failed to link: %s\n", info); - FatalError("GLSL link failure\n"); - } - - return prog; -} - -static void -ephyr_glamor_setup_texturing_shader(struct ephyr_glamor *glamor) -{ - const char *vs_source = - "attribute vec2 texcoord;\n" - "attribute vec2 position;\n" - "varying vec2 t;\n" - "\n" - "void main()\n" - "{\n" - " t = texcoord;\n" - " gl_Position = vec4(position, 0, 1);\n" - "}\n"; - - const char *fs_source = - "#ifdef GL_ES\n" - "precision mediump float;\n" - "#endif\n" - "\n" - "varying vec2 t;\n" - "uniform sampler2D s; /* initially 0 */\n" - "\n" - "void main()\n" - "{\n" - " gl_FragColor = texture2D(s, t);\n" - "}\n"; - - GLuint fs, vs, prog; - - vs = ephyr_glamor_compile_glsl_prog(GL_VERTEX_SHADER, vs_source); - fs = ephyr_glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, fs_source); - prog = ephyr_glamor_build_glsl_prog(vs, fs); - - glamor->texture_shader = prog; - glamor->texture_shader_position_loc = glGetAttribLocation(prog, "position"); - assert(glamor->texture_shader_position_loc != -1); - glamor->texture_shader_texcoord_loc = glGetAttribLocation(prog, "texcoord"); - assert(glamor->texture_shader_texcoord_loc != -1); -} - -xcb_connection_t * -ephyr_glamor_connect(void) -{ - dpy = XOpenDisplay(NULL); - if (!dpy) - return NULL; - - XSetEventQueueOwner(dpy, XCBOwnsEventQueue); - - return XGetXCBConnection(dpy); -} - -void -ephyr_glamor_set_texture(struct ephyr_glamor *glamor, uint32_t tex) -{ - glamor->tex = tex; -} - -static void -ephyr_glamor_set_vertices(struct ephyr_glamor *glamor) -{ - glVertexAttribPointer(glamor->texture_shader_position_loc, - 2, GL_FLOAT, FALSE, 0, (void *) 0); - glVertexAttribPointer(glamor->texture_shader_texcoord_loc, - 2, GL_FLOAT, FALSE, 0, (void *) (sizeof (float) * 8)); - - glEnableVertexAttribArray(glamor->texture_shader_position_loc); - glEnableVertexAttribArray(glamor->texture_shader_texcoord_loc); -} - -void -ephyr_glamor_damage_redisplay(struct ephyr_glamor *glamor, - struct pixman_region16 *damage) -{ - GLint old_vao; - - /* Skip presenting the output in this mode. Presentation is - * expensive, and if we're just running the X Test suite headless, - * nobody's watching. - */ - if (ephyr_glamor_skip_present) - return; - - glXMakeCurrent(dpy, glamor->glx_win, glamor->ctx); - - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &old_vao); - glBindVertexArray(glamor->vao); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glUseProgram(glamor->texture_shader); - glViewport(0, 0, glamor->width, glamor->height); - if (!ephyr_glamor_gles2) - glDisable(GL_COLOR_LOGIC_OP); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, glamor->tex); - glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - - glBindVertexArray(old_vao); - - glXSwapBuffers(dpy, glamor->glx_win); -} - -/** - * Xlib-based handling of xcb events for glamor. - * - * We need to let the Xlib event filtering run on the event so that - * Mesa's dri2_glx.c userspace event mangling gets run, and we - * correctly get our invalidate events propagated into the driver. - */ -void -ephyr_glamor_process_event(xcb_generic_event_t *xev) -{ - - uint32_t response_type = xev->response_type & 0x7f; - /* Note the types on wire_to_event: there's an Xlib XEvent (with - * the broken types) that it returns, and a protocol xEvent that - * it inspects. - */ - Bool (*wire_to_event)(Display *dpy, XEvent *ret, xEvent *event); - - XLockDisplay(dpy); - /* Set the event handler to NULL to get access to the current one. */ - wire_to_event = XESetWireToEvent(dpy, response_type, NULL); - if (wire_to_event) { - XEvent processed_event; - - /* OK they had an event handler. Plug it back in, and call - * through to it. - */ - XESetWireToEvent(dpy, response_type, wire_to_event); - xev->sequence = LastKnownRequestProcessed(dpy); - wire_to_event(dpy, &processed_event, (xEvent *)xev); - } - XUnlockDisplay(dpy); -} - -static int -ephyr_glx_error_handler(Display * _dpy, XErrorEvent * ev) -{ - return 0; -} - -struct ephyr_glamor * -ephyr_glamor_glx_screen_init(xcb_window_t win) -{ - int (*oldErrorHandler) (Display *, XErrorEvent *); - static const float position[] = { - -1, -1, - 1, -1, - 1, 1, - -1, 1, - 0, 1, - 1, 1, - 1, 0, - 0, 0, - }; - GLint old_vao; - - GLXContext ctx; - struct ephyr_glamor *glamor; - GLXWindow glx_win; - - glamor = calloc(1, sizeof(struct ephyr_glamor)); - if (!glamor) { - FatalError("malloc"); - return NULL; - } - - glx_win = glXCreateWindow(dpy, fb_config, win, NULL); - - if (ephyr_glamor_gles2) { - static const int context_attribs[] = { - GLX_CONTEXT_MAJOR_VERSION_ARB, 2, - GLX_CONTEXT_MINOR_VERSION_ARB, 0, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_ES_PROFILE_BIT_EXT, - 0, - }; - if (epoxy_has_glx_extension(dpy, DefaultScreen(dpy), - "GLX_EXT_create_context_es2_profile")) { - ctx = glXCreateContextAttribsARB(dpy, fb_config, NULL, True, - context_attribs); - } else { - FatalError("Xephyr -glamor_gles2 requires " - "GLX_EXT_create_context_es2_profile\n"); - } - } else { - if (epoxy_has_glx_extension(dpy, DefaultScreen(dpy), - "GLX_ARB_create_context")) { - static const int context_attribs[] = { - GLX_CONTEXT_PROFILE_MASK_ARB, - GLX_CONTEXT_CORE_PROFILE_BIT_ARB, - GLX_CONTEXT_MAJOR_VERSION_ARB, - GLAMOR_GL_CORE_VER_MAJOR, - GLX_CONTEXT_MINOR_VERSION_ARB, - GLAMOR_GL_CORE_VER_MINOR, - 0, - }; - oldErrorHandler = XSetErrorHandler(ephyr_glx_error_handler); - ctx = glXCreateContextAttribsARB(dpy, fb_config, NULL, True, - context_attribs); - XSync(dpy, False); - XSetErrorHandler(oldErrorHandler); - } else { - ctx = NULL; - } - - if (!ctx) - ctx = glXCreateContext(dpy, visual_info, NULL, True); - } - if (ctx == NULL) - FatalError("glXCreateContext failed\n"); - - if (!glXMakeCurrent(dpy, glx_win, ctx)) - FatalError("glXMakeCurrent failed\n"); - - glamor->ctx = ctx; - glamor->win = win; - glamor->glx_win = glx_win; - ephyr_glamor_setup_texturing_shader(glamor); - - glGenVertexArrays(1, &glamor->vao); - glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &old_vao); - glBindVertexArray(glamor->vao); - - glGenBuffers(1, &glamor->vbo); - - glBindBuffer(GL_ARRAY_BUFFER, glamor->vbo); - glBufferData(GL_ARRAY_BUFFER, sizeof (position), position, GL_STATIC_DRAW); - - ephyr_glamor_set_vertices(glamor); - glBindVertexArray(old_vao); - - return glamor; -} - -void -ephyr_glamor_glx_screen_fini(struct ephyr_glamor *glamor) -{ - glXMakeCurrent(dpy, None, NULL); - glXDestroyContext(dpy, glamor->ctx); - glXDestroyWindow(dpy, glamor->glx_win); - - free(glamor); -} - -xcb_visualtype_t * -ephyr_glamor_get_visual(void) -{ - xcb_screen_t *xscreen = - xcb_aux_get_screen(XGetXCBConnection(dpy), DefaultScreen(dpy)); - int attribs[] = { - GLX_RENDER_TYPE, GLX_RGBA_BIT, - GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - GLX_DOUBLEBUFFER, 1, - None - }; - int event_base = 0, error_base = 0, nelements; - GLXFBConfig *fbconfigs; - - if (!glXQueryExtension (dpy, &error_base, &event_base)) - FatalError("Couldn't find GLX extension\n"); - - fbconfigs = glXChooseFBConfig(dpy, DefaultScreen(dpy), attribs, &nelements); - if (!nelements) - FatalError("Couldn't choose an FBConfig\n"); - fb_config = fbconfigs[0]; - free(fbconfigs); - - visual_info = glXGetVisualFromFBConfig(dpy, fb_config); - if (visual_info == NULL) - FatalError("Couldn't get RGB visual\n"); - - return xcb_aux_find_visual_by_id(xscreen, visual_info->visualid); -} - -void -ephyr_glamor_set_window_size(struct ephyr_glamor *glamor, - unsigned width, unsigned height) -{ - if (!glamor) - return; - - glamor->width = width; - glamor->height = height; -} diff --git a/hw/kdrive/ephyr/ephyr_glamor_glx.h b/hw/kdrive/ephyr/ephyr_glamor_glx.h deleted file mode 100644 index 0c238cf5b..000000000 --- a/hw/kdrive/ephyr/ephyr_glamor_glx.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright © 2013 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -/** - * ephyr_glamor_glx.h - * - * Prototypes exposed by ephyr_glamor_glx.c, without including any - * server headers. - */ - -#include -#include "dix-config.h" - -struct ephyr_glamor; -struct pixman_region16; - -xcb_connection_t * -ephyr_glamor_connect(void); - -void -ephyr_glamor_set_texture(struct ephyr_glamor *ephyr_glamor, uint32_t tex); - -xcb_visualtype_t * -ephyr_glamor_get_visual(void); - -struct ephyr_glamor * -ephyr_glamor_glx_screen_init(xcb_window_t win); - -void -ephyr_glamor_glx_screen_fini(struct ephyr_glamor *glamor); - -#ifdef GLAMOR -void -ephyr_glamor_set_window_size(struct ephyr_glamor *glamor, - unsigned width, unsigned height); - -void -ephyr_glamor_damage_redisplay(struct ephyr_glamor *glamor, - struct pixman_region16 *damage); - -void -ephyr_glamor_process_event(xcb_generic_event_t *xev); - -#else /* !GLAMOR */ - -static inline void -ephyr_glamor_set_window_size(struct ephyr_glamor *glamor, - unsigned width, unsigned height) -{ -} - -static inline void -ephyr_glamor_damage_redisplay(struct ephyr_glamor *glamor, - struct pixman_region16 *damage) -{ -} - -static inline void -ephyr_glamor_process_event(xcb_generic_event_t *xev) -{ -} - -#endif /* !GLAMOR */ diff --git a/hw/kdrive/ephyr/ephyr_glamor_xv.c b/hw/kdrive/ephyr/ephyr_glamor_xv.c deleted file mode 100644 index 4dd15cf41..000000000 --- a/hw/kdrive/ephyr/ephyr_glamor_xv.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright © 2014 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "kdrive.h" -#include "kxv.h" -#include "ephyr.h" -#include "glamor_priv.h" - -#include -#include "fourcc.h" - -#define NUM_FORMATS 3 - -static KdVideoFormatRec Formats[NUM_FORMATS] = { - {15, TrueColor}, {16, TrueColor}, {24, TrueColor} -}; - -static void -ephyr_glamor_xv_stop_video(KdScreenInfo *screen, void *data, Bool cleanup) -{ - if (!cleanup) - return; - - glamor_xv_stop_video(data); -} - -static int -ephyr_glamor_xv_set_port_attribute(KdScreenInfo *screen, - Atom attribute, INT32 value, void *data) -{ - return glamor_xv_set_port_attribute(data, attribute, value); -} - -static int -ephyr_glamor_xv_get_port_attribute(KdScreenInfo *screen, - Atom attribute, INT32 *value, void *data) -{ - return glamor_xv_get_port_attribute(data, attribute, value); -} - -static void -ephyr_glamor_xv_query_best_size(KdScreenInfo *screen, - Bool motion, - short vid_w, short vid_h, - short drw_w, short drw_h, - unsigned int *p_w, unsigned int *p_h, - void *data) -{ - *p_w = drw_w; - *p_h = drw_h; -} - -static int -ephyr_glamor_xv_query_image_attributes(KdScreenInfo *screen, - int id, - unsigned short *w, unsigned short *h, - int *pitches, int *offsets) -{ - return glamor_xv_query_image_attributes(id, w, h, pitches, offsets); -} - -static int -ephyr_glamor_xv_put_image(KdScreenInfo *screen, - DrawablePtr pDrawable, - short src_x, short src_y, - short drw_x, short drw_y, - short src_w, short src_h, - short drw_w, short drw_h, - int id, - unsigned char *buf, - short width, - short height, - Bool sync, - RegionPtr clipBoxes, void *data) -{ - return glamor_xv_put_image(data, pDrawable, - src_x, src_y, - drw_x, drw_y, - src_w, src_h, - drw_w, drw_h, - id, buf, width, height, sync, clipBoxes); -} - -void -ephyr_glamor_xv_init(ScreenPtr screen) -{ - KdVideoAdaptorRec *adaptor; - glamor_port_private *port_privates; - KdVideoEncodingRec encoding = { - 0, - "XV_IMAGE", - /* These sizes should probably be GL_MAX_TEXTURE_SIZE instead - * of 2048, but our context isn't set up yet. - */ - 2048, 2048, - {1, 1} - }; - int i; - - glamor_xv_core_init(screen); - - adaptor = xnfcalloc(1, sizeof(*adaptor)); - - adaptor->name = "glamor textured video"; - adaptor->type = XvWindowMask | XvInputMask | XvImageMask; - adaptor->flags = 0; - adaptor->nEncodings = 1; - adaptor->pEncodings = &encoding; - - adaptor->pFormats = Formats; - adaptor->nFormats = NUM_FORMATS; - - adaptor->nPorts = 16; /* Some absurd number */ - port_privates = xnfcalloc(adaptor->nPorts, - sizeof(glamor_port_private)); - adaptor->pPortPrivates = xnfcalloc(adaptor->nPorts, - sizeof(glamor_port_private *)); - for (i = 0; i < adaptor->nPorts; i++) { - adaptor->pPortPrivates[i].ptr = &port_privates[i]; - glamor_xv_init_port(&port_privates[i]); - } - - adaptor->pAttributes = glamor_xv_attributes; - adaptor->nAttributes = glamor_xv_num_attributes; - - adaptor->pImages = glamor_xv_images; - adaptor->nImages = glamor_xv_num_images; - - adaptor->StopVideo = ephyr_glamor_xv_stop_video; - adaptor->SetPortAttribute = ephyr_glamor_xv_set_port_attribute; - adaptor->GetPortAttribute = ephyr_glamor_xv_get_port_attribute; - adaptor->QueryBestSize = ephyr_glamor_xv_query_best_size; - adaptor->PutImage = ephyr_glamor_xv_put_image; - adaptor->QueryImageAttributes = ephyr_glamor_xv_query_image_attributes; - - KdXVScreenInit(screen, adaptor, 1); -} diff --git a/hw/kdrive/ephyr/ephyrcursor.c b/hw/kdrive/ephyr/ephyrcursor.c deleted file mode 100644 index f991899c5..000000000 --- a/hw/kdrive/ephyr/ephyrcursor.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright © 2014 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: - * Adam Jackson - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "ephyr.h" -#include "ephyrlog.h" -#include "hostx.h" -#include "cursorstr.h" -#include -#include - -static DevPrivateKeyRec ephyrCursorPrivateKey; - -typedef struct _ephyrCursor { - xcb_cursor_t cursor; -} ephyrCursorRec, *ephyrCursorPtr; - -static ephyrCursorPtr -ephyrGetCursor(CursorPtr cursor) -{ - return dixGetPrivateAddr(&cursor->devPrivates, &ephyrCursorPrivateKey); -} - -static void -ephyrRealizeCoreCursor(EphyrScrPriv *scr, CursorPtr cursor) -{ - ephyrCursorPtr hw = ephyrGetCursor(cursor); - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_pixmap_t source, mask; - xcb_image_t *image; - xcb_gcontext_t gc; - int w = cursor->bits->width, h = cursor->bits->height; - uint32_t gcmask = XCB_GC_FUNCTION | - XCB_GC_PLANE_MASK | - XCB_GC_FOREGROUND | - XCB_GC_BACKGROUND | - XCB_GC_CLIP_MASK; - uint32_t val[] = { - XCB_GX_COPY, /* function */ - ~0, /* planemask */ - 1L, /* foreground */ - 0L, /* background */ - None, /* clipmask */ - }; - - source = xcb_generate_id(conn); - mask = xcb_generate_id(conn); - xcb_create_pixmap(conn, 1, source, scr->win, w, h); - xcb_create_pixmap(conn, 1, mask, scr->win, w, h); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, source, gcmask, val); - - image = xcb_image_create_native(conn, w, h, XCB_IMAGE_FORMAT_XY_BITMAP, - 1, NULL, ~0, NULL); - image->data = cursor->bits->source; - xcb_image_put(conn, source, gc, image, 0, 0, 0); - xcb_image_destroy(image); - - image = xcb_image_create_native(conn, w, h, XCB_IMAGE_FORMAT_XY_BITMAP, - 1, NULL, ~0, NULL); - image->data = cursor->bits->mask; - xcb_image_put(conn, mask, gc, image, 0, 0, 0); - xcb_image_destroy(image); - - xcb_free_gc(conn, gc); - - hw->cursor = xcb_generate_id(conn); - xcb_create_cursor(conn, hw->cursor, source, mask, - cursor->foreRed, cursor->foreGreen, cursor->foreBlue, - cursor->backRed, cursor->backGreen, cursor->backBlue, - cursor->bits->xhot, cursor->bits->yhot); - - xcb_free_pixmap(conn, source); - xcb_free_pixmap(conn, mask); -} - -static xcb_render_pictformat_t -get_argb_format(void) -{ - static xcb_render_pictformat_t format; - if (format == None) { - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_render_query_pict_formats_cookie_t cookie; - xcb_render_query_pict_formats_reply_t *formats; - - cookie = xcb_render_query_pict_formats(conn); - formats = - xcb_render_query_pict_formats_reply(conn, cookie, NULL); - - format = - xcb_render_util_find_standard_format(formats, - XCB_PICT_STANDARD_ARGB_32)->id; - - free(formats); - } - - return format; -} - -static void -ephyrRealizeARGBCursor(EphyrScrPriv *scr, CursorPtr cursor) -{ - ephyrCursorPtr hw = ephyrGetCursor(cursor); - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_gcontext_t gc; - xcb_pixmap_t source; - xcb_render_picture_t picture; - xcb_image_t *image; - int w = cursor->bits->width, h = cursor->bits->height; - - /* dix' storage is PICT_a8r8g8b8 */ - source = xcb_generate_id(conn); - xcb_create_pixmap(conn, 32, source, scr->win, w, h); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, source, 0, NULL); - image = xcb_image_create_native(conn, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP, - 32, NULL, ~0, NULL); - image->data = (void *)cursor->bits->argb; - xcb_image_put(conn, source, gc, image, 0, 0, 0); - xcb_free_gc(conn, gc); - xcb_image_destroy(image); - - picture = xcb_generate_id(conn); - xcb_render_create_picture(conn, picture, source, get_argb_format(), - 0, NULL); - xcb_free_pixmap(conn, source); - - hw->cursor = xcb_generate_id(conn); - xcb_render_create_cursor(conn, hw->cursor, picture, - cursor->bits->xhot, cursor->bits->yhot); - - xcb_render_free_picture(conn, picture); -} - -static Bool -can_argb_cursor(void) -{ - static const xcb_render_query_version_reply_t *v; - - if (!v) - v = xcb_render_util_query_version(hostx_get_xcbconn()); - - return v->major_version == 0 && v->minor_version >= 5; -} - -static Bool -ephyrRealizeCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor) -{ - KdScreenPriv(screen); - KdScreenInfo *kscr = pScreenPriv->screen; - EphyrScrPriv *scr = kscr->driver; - - if (cursor->bits->argb && can_argb_cursor()) - ephyrRealizeARGBCursor(scr, cursor); - else - { - ephyrRealizeCoreCursor(scr, cursor); - } - return TRUE; -} - -static Bool -ephyrUnrealizeCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor) -{ - ephyrCursorPtr hw = ephyrGetCursor(cursor); - - if (hw->cursor) { - xcb_free_cursor(hostx_get_xcbconn(), hw->cursor); - hw->cursor = None; - } - - return TRUE; -} - -static void -ephyrSetCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor, int x, - int y) -{ - KdScreenPriv(screen); - KdScreenInfo *kscr = pScreenPriv->screen; - EphyrScrPriv *scr = kscr->driver; - uint32_t attr = None; - - if (cursor) - attr = ephyrGetCursor(cursor)->cursor; - else - attr = hostx_get_empty_cursor(); - - xcb_change_window_attributes(hostx_get_xcbconn(), scr->win, - XCB_CW_CURSOR, &attr); - xcb_flush(hostx_get_xcbconn()); -} - -static void -ephyrMoveCursor(DeviceIntPtr dev, ScreenPtr screen, int x, int y) -{ -} - -static Bool -ephyrDeviceCursorInitialize(DeviceIntPtr dev, ScreenPtr screen) -{ - return TRUE; -} - -static void -ephyrDeviceCursorCleanup(DeviceIntPtr dev, ScreenPtr screen) -{ -} - -miPointerSpriteFuncRec EphyrPointerSpriteFuncs = { - ephyrRealizeCursor, - ephyrUnrealizeCursor, - ephyrSetCursor, - ephyrMoveCursor, - ephyrDeviceCursorInitialize, - ephyrDeviceCursorCleanup -}; - -Bool -ephyrCursorInit(ScreenPtr screen) -{ - if (!dixRegisterPrivateKey(&ephyrCursorPrivateKey, PRIVATE_CURSOR_BITS, - sizeof(ephyrCursorRec))) - return FALSE; - - miPointerInitialize(screen, - &EphyrPointerSpriteFuncs, - &ephyrPointerScreenFuncs, FALSE); - - return TRUE; -} diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c deleted file mode 100644 index 020461db2..000000000 --- a/hw/kdrive/ephyr/ephyrinit.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2004 Nokia - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Nokia not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Nokia makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "ephyr.h" -#include "ephyrlog.h" -#include "glx_extinit.h" - -extern Window EphyrPreExistingHostWin; -extern Bool EphyrWantGrayScale; -extern Bool EphyrWantResize; -extern Bool EphyrWantNoHostGrab; -extern Bool kdHasPointer; -extern Bool kdHasKbd; -extern Bool ephyr_glamor, ephyr_glamor_gles2, ephyr_glamor_skip_present; - -extern Bool ephyrNoXV; - -void processScreenOrOutputArg(const char *screen_size, const char *output, char *parent_id); -void processOutputArg(const char *output, char *parent_id); -void processScreenArg(const char *screen_size, char *parent_id); - -int -main(int argc, char *argv[], char *envp[]) -{ - hostx_use_resname(basename(argv[0]), 0); - return dix_main(argc, argv, envp); -} - -void -InitCard(char *name) -{ - EPHYR_DBG("mark"); - KdCardInfoAdd(&ephyrFuncs, 0); -} - -void -InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv) -{ - KdInitOutput(pScreenInfo, argc, argv); -} - -void -InitInput(int argc, char **argv) -{ - KdKeyboardInfo *ki; - KdPointerInfo *pi; - - if (!SeatId) { - KdAddKeyboardDriver(&EphyrKeyboardDriver); - KdAddPointerDriver(&EphyrMouseDriver); - - if (!kdHasKbd) { - ki = KdNewKeyboard(); - if (!ki) - FatalError("Couldn't create Xephyr keyboard\n"); - ki->driver = &EphyrKeyboardDriver; - KdAddKeyboard(ki); - } - - if (!kdHasPointer) { - pi = KdNewPointer(); - if (!pi) - FatalError("Couldn't create Xephyr pointer\n"); - pi->driver = &EphyrMouseDriver; - KdAddPointer(pi); - } - } - - KdInitInput(); -} - -void -CloseInput(void) -{ - KdCloseInput(); -} - -#if INPUTTHREAD -/** This function is called in Xserver/os/inputthread.c when starting - the input thread. */ -void -ddxInputThreadInit(void) -{ -} -#endif - -#ifdef DDXBEFORERESET -void -ddxBeforeReset(void) -{ -} -#endif - -void -ddxUseMsg(void) -{ - KdUseMsg(); - - ErrorF("\nXephyr Option Usage:\n"); - ErrorF("-parent Use existing window as Xephyr root win\n"); - ErrorF("-sw-cursor Render cursors in software in Xephyr\n"); - ErrorF("-fullscreen Attempt to run Xephyr fullscreen\n"); - ErrorF("-output Attempt to run Xephyr fullscreen (restricted to given output geometry)\n"); - ErrorF("-grayscale Simulate 8bit grayscale\n"); - ErrorF("-resizeable Make Xephyr windows resizeable\n"); -#ifdef GLAMOR - ErrorF("-glamor Enable 2D acceleration using glamor\n"); - ErrorF("-glamor_gles2 Enable 2D acceleration using glamor (with GLES2 only)\n"); - ErrorF("-glamor-skip-present Skip presenting the output when using glamor (for internal testing optimization)\n"); -#endif - ErrorF - ("-fakexa Simulate acceleration using software rendering\n"); - ErrorF("-verbosity Set log verbosity level\n"); - ErrorF("-noxv do not use XV\n"); - ErrorF("-name [name] define the name in the WM_CLASS property\n"); - ErrorF - ("-title [title] set the window title in the WM_NAME property\n"); - ErrorF("-no-host-grab Disable grabbing the keyboard and mouse.\n"); - ErrorF("\n"); -} - -void -processScreenOrOutputArg(const char *screen_size, const char *output, char *parent_id) -{ - KdCardInfo *card; - - InitCard(0); /*Put each screen on a separate card */ - card = KdCardInfoLast(); - - if (card) { - KdScreenInfo *screen; - unsigned long p_id = 0; - Bool use_geometry; - - screen = KdScreenInfoAdd(card); - KdParseScreen(screen, screen_size); - screen->driver = calloc(1, sizeof(EphyrScrPriv)); - if (!screen->driver) - FatalError("Couldn't alloc screen private\n"); - - if (parent_id) { - p_id = strtol(parent_id, NULL, 0); - } - - use_geometry = (strchr(screen_size, '+') != NULL); - EPHYR_DBG("screen number:%d\n", screen->mynum); - hostx_add_screen(screen, p_id, screen->mynum, use_geometry, output); - } - else { - ErrorF("No matching card found!\n"); - } -} - -void -processScreenArg(const char *screen_size, char *parent_id) -{ - processScreenOrOutputArg(screen_size, NULL, parent_id); -} - -void -processOutputArg(const char *output, char *parent_id) -{ - processScreenOrOutputArg("100x100+0+0", output, parent_id); -} - -int -ddxProcessArgument(int argc, char **argv, int i) -{ - static char *parent = NULL; - - EPHYR_DBG("mark argv[%d]='%s'", i, argv[i]); - - if (!strcmp(argv[i], "-parent")) { - if (i + 1 < argc) { - int j; - - /* If parent is specified and a screen argument follows, don't do - * anything, let the -screen handling init the rest */ - for (j = i; j < argc; j++) { - if (!strcmp(argv[j], "-screen")) { - parent = argv[i + 1]; - return 2; - } - } - - processScreenArg("100x100", argv[i + 1]); - return 2; - } - - UseMsg(); - exit(1); - } - else if (!strcmp(argv[i], "-screen")) { - if ((i + 1) < argc) { - processScreenArg(argv[i + 1], parent); - parent = NULL; - return 2; - } - - UseMsg(); - exit(1); - } - else if (!strcmp(argv[i], "-output")) { - if (i + 1 < argc) { - processOutputArg(argv[i + 1], NULL); - return 2; - } - - UseMsg(); - exit(1); - } - else if (!strcmp(argv[i], "-sw-cursor")) { - hostx_use_sw_cursor(); - return 1; - } - else if (!strcmp(argv[i], "-host-cursor")) { - /* Compatibility with the old command line argument, now the default. */ - return 1; - } - else if (!strcmp(argv[i], "-fullscreen")) { - hostx_use_fullscreen(); - return 1; - } - else if (!strcmp(argv[i], "-grayscale")) { - EphyrWantGrayScale = 1; - return 1; - } - else if (!strcmp(argv[i], "-resizeable")) { - EphyrWantResize = 1; - return 1; - } -#ifdef GLAMOR - else if (!strcmp (argv[i], "-glamor")) { - ephyr_glamor = TRUE; - ephyrFuncs.initAccel = ephyr_glamor_init; - ephyrFuncs.enableAccel = ephyr_glamor_enable; - ephyrFuncs.disableAccel = ephyr_glamor_disable; - ephyrFuncs.finiAccel = ephyr_glamor_fini; - return 1; - } - else if (!strcmp (argv[i], "-glamor_gles2")) { - ephyr_glamor = TRUE; - ephyr_glamor_gles2 = TRUE; - ephyrFuncs.initAccel = ephyr_glamor_init; - ephyrFuncs.enableAccel = ephyr_glamor_enable; - ephyrFuncs.disableAccel = ephyr_glamor_disable; - ephyrFuncs.finiAccel = ephyr_glamor_fini; - return 1; - } - else if (!strcmp (argv[i], "-glamor-skip-present")) { - ephyr_glamor_skip_present = TRUE; - return 1; - } -#endif - else if (!strcmp(argv[i], "-fakexa")) { - ephyrFuncs.initAccel = ephyrDrawInit; - ephyrFuncs.enableAccel = ephyrDrawEnable; - ephyrFuncs.disableAccel = ephyrDrawDisable; - ephyrFuncs.finiAccel = ephyrDrawFini; - return 1; - } - else if (!strcmp(argv[i], "-verbosity")) { - if (i + 1 < argc && argv[i + 1][0] != '-') { - int verbosity = atoi(argv[i + 1]); - - LogSetParameter(XLOG_VERBOSITY, verbosity); - EPHYR_LOG("set verbosiry to %d\n", verbosity); - return 2; - } - else { - UseMsg(); - exit(1); - } - } - else if (!strcmp(argv[i], "-noxv")) { - ephyrNoXV = TRUE; - EPHYR_LOG("no XVideo enabled\n"); - return 1; - } - else if (!strcmp(argv[i], "-name")) { - if (i + 1 < argc && argv[i + 1][0] != '-') { - hostx_use_resname(argv[i + 1], 1); - return 2; - } - else { - UseMsg(); - return 0; - } - } - else if (!strcmp(argv[i], "-title")) { - if (i + 1 < argc && argv[i + 1][0] != '-') { - hostx_set_title(argv[i + 1]); - return 2; - } - else { - UseMsg(); - return 0; - } - } - else if (argv[i][0] == ':') { - hostx_set_display_name(argv[i]); - } - /* Xnest compatibility */ - else if (!strcmp(argv[i], "-display")) { - hostx_set_display_name(argv[i + 1]); - return 2; - } - else if (!strcmp(argv[i], "-sync") || - !strcmp(argv[i], "-full") || - !strcmp(argv[i], "-sss") || !strcmp(argv[i], "-install")) { - return 1; - } - else if (!strcmp(argv[i], "-bw") || - !strcmp(argv[i], "-class") || - !strcmp(argv[i], "-geometry") || !strcmp(argv[i], "-scrns")) { - return 2; - } - /* end Xnest compat */ - else if (!strcmp(argv[i], "-no-host-grab")) { - EphyrWantNoHostGrab = 1; - return 1; - } - else if (!strcmp(argv[i], "-sharevts") || - !strcmp(argv[i], "-novtswitch")) { - return 1; - } - else if (!strcmp(argv[i], "-layout")) { - return 2; - } - - return KdProcessArgument(argc, argv, i); -} - -void -OsVendorInit(void) -{ - EPHYR_DBG("mark"); - - if (SeatId) - hostx_use_sw_cursor(); - - if (hostx_want_host_cursor()) - ephyrFuncs.initCursor = &ephyrCursorInit; - - if (serverGeneration == 1) { - if (!KdCardInfoLast()) { - processScreenArg("640x480", NULL); - } - hostx_init(); - } -} - -KdCardFuncs ephyrFuncs = { - ephyrCardInit, /* cardinit */ - ephyrScreenInitialize, /* scrinit */ - ephyrInitScreen, /* initScreen */ - ephyrFinishInitScreen, /* finishInitScreen */ - ephyrCreateResources, /* createRes */ - ephyrScreenFini, /* scrfini */ - ephyrCardFini, /* cardfini */ - - 0, /* initCursor */ - - 0, /* initAccel */ - 0, /* enableAccel */ - 0, /* disableAccel */ - 0, /* finiAccel */ - - ephyrGetColors, /* getColors */ - ephyrPutColors, /* putColors */ - - ephyrCloseScreen, /* closeScreen */ -}; diff --git a/hw/kdrive/ephyr/ephyrlog.h b/hw/kdrive/ephyr/ephyrlog.h deleted file mode 100644 index 744da74c5..000000000 --- a/hw/kdrive/ephyr/ephyrlog.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2007 OpenedHand Ltd - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of OpenedHand Ltd not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. OpenedHand Ltd makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Authors: - * Dodji Seketeli - */ -#ifndef __EPHYRLOG_H__ -#define __EPHYRLOG_H__ - -#include -#include "os.h" - -#ifndef DEBUG -/*we are not in debug mode*/ -#define EPHYR_LOG(...) -#define EPHYR_LOG_ERROR(...) -#endif /*!DEBUG */ - -#define ERROR_LOG_LEVEL 3 -#define INFO_LOG_LEVEL 4 - -#ifndef EPHYR_LOG -#define EPHYR_LOG(...) \ -LogMessageVerb(X_NOTICE, INFO_LOG_LEVEL, "in %s:%d:%s: ",\ - __FILE__, __LINE__, __func__) ; \ -LogMessageVerb(X_NOTICE, INFO_LOG_LEVEL, __VA_ARGS__) -#endif /*nomadik_log */ - -#ifndef EPHYR_LOG_ERROR -#define EPHYR_LOG_ERROR(...) \ -LogMessageVerb(X_NOTICE, ERROR_LOG_LEVEL, "Error:in %s:%d:%s: ",\ - __FILE__, __LINE__, __func__) ; \ -LogMessageVerb(X_NOTICE, ERROR_LOG_LEVEL, __VA_ARGS__) -#endif /*EPHYR_LOG_ERROR */ - -#ifndef EPHYR_RETURN_IF_FAIL -#define EPHYR_RETURN_IF_FAIL(cond) \ -if (!(cond)) {EPHYR_LOG_ERROR("condition %s failed\n", #cond);return;} -#endif /*nomadik_return_if_fail */ - -#ifndef EPHYR_RETURN_VAL_IF_FAIL -#define EPHYR_RETURN_VAL_IF_FAIL(cond,val) \ -if (!(cond)) {EPHYR_LOG_ERROR("condition %s failed\n", #cond);return val;} -#endif /*nomadik_return_val_if_fail */ - -#endif /*__EPHYRLOG_H__*/ diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c deleted file mode 100644 index 2dbddfb8d..000000000 --- a/hw/kdrive/ephyr/ephyrvideo.c +++ /dev/null @@ -1,1253 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2007 OpenedHand Ltd - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of OpenedHand Ltd not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. OpenedHand Ltd makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * OpenedHand Ltd DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL OpenedHand Ltd BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - * - * Authors: - * Dodji Seketeli - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include -#include -#include -#include -#include -#include "ephyrlog.h" -#include "kdrive.h" -#include "kxv.h" -#include "ephyr.h" -#include "hostx.h" - -struct _EphyrXVPriv { - xcb_xv_query_adaptors_reply_t *host_adaptors; - KdVideoAdaptorPtr adaptors; - int num_adaptors; -}; -typedef struct _EphyrXVPriv EphyrXVPriv; - -struct _EphyrPortPriv { - int port_number; - KdVideoAdaptorPtr current_adaptor; - EphyrXVPriv *xv_priv; - unsigned char *image_buf; - int image_buf_size; - int image_id; - int drw_x, drw_y, drw_w, drw_h; - int src_x, src_y, src_w, src_h; - int image_width, image_height; -}; -typedef struct _EphyrPortPriv EphyrPortPriv; - -static Bool ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom); - -static EphyrXVPriv *ephyrXVPrivNew(void); -static void ephyrXVPrivDelete(EphyrXVPriv * a_this); -static Bool ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this); -static Bool ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this); -static Bool ephyrXVPrivRegisterAdaptors(EphyrXVPriv * a_this, - ScreenPtr a_screen); - -static Bool ephyrXVPrivIsAttrValueValid(XvAttributePtr a_attrs, - int a_attrs_len, - const char *a_attr_name, - int a_attr_value, Bool *a_is_valid); - -static Bool ephyrXVPrivGetImageBufSize(int a_port_id, - int a_image_id, - unsigned short a_width, - unsigned short a_height, int *a_size); - -static Bool ephyrXVPrivSaveImageToPortPriv(EphyrPortPriv * a_port_priv, - const unsigned char *a_image, - int a_image_len); - -static void ephyrStopVideo(KdScreenInfo * a_info, - void *a_xv_priv, Bool a_exit); - -static int ephyrSetPortAttribute(KdScreenInfo * a_info, - Atom a_attr_name, - int a_attr_value, void *a_port_priv); - -static int ephyrGetPortAttribute(KdScreenInfo * a_screen_info, - Atom a_attr_name, - int *a_attr_value, void *a_port_priv); - -static void ephyrQueryBestSize(KdScreenInfo * a_info, - Bool a_motion, - short a_src_w, - short a_src_h, - short a_drw_w, - short a_drw_h, - unsigned int *a_prefered_w, - unsigned int *a_prefered_h, void *a_port_priv); - -static int ephyrPutImage(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_src_x, - short a_src_y, - short a_drw_x, - short a_drw_y, - short a_src_w, - short a_src_h, - short a_drw_w, - short a_drw_h, - int a_id, - unsigned char *a_buf, - short a_width, - short a_height, - Bool a_sync, - RegionPtr a_clipping_region, void *a_port_priv); - -static int ephyrReputImage(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_drw_x, - short a_drw_y, - RegionPtr a_clipping_region, void *a_port_priv); - -static int ephyrPutVideo(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clip_region, void *a_port_priv); - -static int ephyrGetVideo(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clip_region, void *a_port_priv); - -static int ephyrPutStill(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clip_region, void *a_port_priv); - -static int ephyrGetStill(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clip_region, void *a_port_priv); - -static int ephyrQueryImageAttributes(KdScreenInfo * a_info, - int a_id, - unsigned short *a_w, - unsigned short *a_h, - int *a_pitches, int *a_offsets); -static int s_base_port_id; - -/************** - * - * ************/ - -static Bool -adaptor_has_flags(const xcb_xv_adaptor_info_t *adaptor, uint32_t flags) -{ - return (adaptor->type & flags) == flags; -} - -static Bool -ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_intern_atom_cookie_t cookie; - xcb_intern_atom_reply_t *reply; - const char *atom_name = NULL; - - EPHYR_RETURN_VAL_IF_FAIL(a_host_atom, FALSE); - - if (!ValidAtom(a_local_atom)) - return FALSE; - - atom_name = NameForAtom(a_local_atom); - - if (!atom_name) - return FALSE; - - cookie = xcb_intern_atom(conn, FALSE, strlen(atom_name), atom_name); - reply = xcb_intern_atom_reply(conn, cookie, NULL); - if (!reply || reply->atom == None) { - EPHYR_LOG_ERROR("no atom for string %s defined in host X\n", atom_name); - return FALSE; - } - - *a_host_atom = reply->atom; - free(reply); - - return TRUE; -} - -/************** - * - * ************/ - -Bool -ephyrInitVideo(ScreenPtr pScreen) -{ - Bool is_ok = FALSE; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - static EphyrXVPriv *xv_priv; - - EPHYR_LOG("enter\n"); - - if (screen->fb.bitsPerPixel == 8) { - EPHYR_LOG_ERROR("8 bits depth not supported\n"); - return FALSE; - } - - if (!hostx_has_extension(&xcb_xv_id)) { - EPHYR_LOG_ERROR("Host has no XVideo extension\n"); - return FALSE; - } - - if (!xv_priv) { - xv_priv = ephyrXVPrivNew(); - } - if (!xv_priv) { - EPHYR_LOG_ERROR("failed to create xv_priv\n"); - goto out; - } - - if (!ephyrXVPrivRegisterAdaptors(xv_priv, pScreen)) { - EPHYR_LOG_ERROR("failed to register adaptors\n"); - goto out; - } - is_ok = TRUE; - - out: - return is_ok; -} - -static EphyrXVPriv * -ephyrXVPrivNew(void) -{ - EphyrXVPriv *xv_priv = NULL; - - EPHYR_LOG("enter\n"); - - xv_priv = calloc(1, sizeof(EphyrXVPriv)); - if (!xv_priv) { - EPHYR_LOG_ERROR("failed to create EphyrXVPriv\n"); - goto error; - } - - if (!ephyrXVPrivQueryHostAdaptors(xv_priv)) { - EPHYR_LOG_ERROR("failed to query the host x for xv properties\n"); - goto error; - } - if (!ephyrXVPrivSetAdaptorsHooks(xv_priv)) { - EPHYR_LOG_ERROR("failed to set xv_priv hooks\n"); - goto error; - } - - EPHYR_LOG("leave\n"); - return xv_priv; - - error: - if (xv_priv) { - ephyrXVPrivDelete(xv_priv); - xv_priv = NULL; - } - return NULL; -} - -static void -ephyrXVPrivDelete(EphyrXVPriv * a_this) -{ - EPHYR_LOG("enter\n"); - - if (!a_this) - return; - if (a_this->host_adaptors) { - free(a_this->host_adaptors); - a_this->host_adaptors = NULL; - } - free(a_this->adaptors); - a_this->adaptors = NULL; - free(a_this); - EPHYR_LOG("leave\n"); -} - -static Bool -translate_video_encodings(KdVideoAdaptorPtr adaptor, - xcb_xv_adaptor_info_t *host_adaptor) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - int i; - xcb_xv_query_encodings_cookie_t cookie; - xcb_xv_query_encodings_reply_t *reply; - xcb_xv_encoding_info_iterator_t encoding_it; - - cookie = xcb_xv_query_encodings(conn, host_adaptor->base_id); - reply = xcb_xv_query_encodings_reply(conn, cookie, NULL); - if (!reply) - return FALSE; - - adaptor->nEncodings = reply->num_encodings; - adaptor->pEncodings = calloc(adaptor->nEncodings, - sizeof(*adaptor->pEncodings)); - if (!adaptor->pEncodings) { - free(reply); - return FALSE; - } - - encoding_it = xcb_xv_query_encodings_info_iterator(reply); - for (i = 0; i < adaptor->nEncodings; i++) { - xcb_xv_encoding_info_t *encoding_info = encoding_it.data; - KdVideoEncodingPtr encoding = &adaptor->pEncodings[i]; - - encoding->id = encoding_info->encoding; - encoding->name = strndup(xcb_xv_encoding_info_name(encoding_info), - encoding_info->name_size); - encoding->width = encoding_info->width; - encoding->height = encoding_info->height; - encoding->rate.numerator = encoding_info->rate.numerator; - encoding->rate.denominator = encoding_info->rate.denominator; - - xcb_xv_encoding_info_next(&encoding_it); - } - - free(reply); - return TRUE; -} - -static Bool -translate_xv_attributes(KdVideoAdaptorPtr adaptor, - xcb_xv_adaptor_info_t *host_adaptor) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - int i = 0; - xcb_xv_attribute_info_iterator_t it; - xcb_xv_query_port_attributes_cookie_t cookie = - xcb_xv_query_port_attributes(conn, host_adaptor->base_id); - xcb_xv_query_port_attributes_reply_t *reply = - xcb_xv_query_port_attributes_reply(conn, cookie, NULL); - - if (!reply) - return FALSE; - - adaptor->nAttributes = reply->num_attributes; - adaptor->pAttributes = calloc(reply->num_attributes, - sizeof(*adaptor->pAttributes)); - if (!adaptor->pAttributes) { - EPHYR_LOG_ERROR("failed to allocate attributes\n"); - free(reply); - return FALSE; - } - - it = xcb_xv_query_port_attributes_attributes_iterator(reply); - for (i = 0; i < reply->num_attributes; i++) { - XvAttributePtr attribute = &adaptor->pAttributes[i]; - - attribute->flags = it.data->flags; - attribute->min_value = it.data->min; - attribute->max_value = it.data->max; - attribute->name = strndup(xcb_xv_attribute_info_name(it.data), - it.data->size); - - /* make sure atoms of attrs names are created in xephyr */ - MakeAtom(xcb_xv_attribute_info_name(it.data), it.data->size, TRUE); - - xcb_xv_attribute_info_next(&it); - } - - free(reply); - return TRUE; -} - -static Bool -translate_xv_image_formats(KdVideoAdaptorPtr adaptor, - xcb_xv_adaptor_info_t *host_adaptor) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - int i = 0; - xcb_xv_list_image_formats_cookie_t cookie = - xcb_xv_list_image_formats(conn, host_adaptor->base_id); - xcb_xv_list_image_formats_reply_t *reply = - xcb_xv_list_image_formats_reply(conn, cookie, NULL); - xcb_xv_image_format_info_t *formats; - - if (!reply) - return FALSE; - - adaptor->nImages = reply->num_formats; - adaptor->pImages = calloc(reply->num_formats, sizeof(XvImageRec)); - if (!adaptor->pImages) { - free(reply); - return FALSE; - } - - formats = xcb_xv_list_image_formats_format(reply); - for (i = 0; i < reply->num_formats; i++) { - XvImagePtr image = &adaptor->pImages[i]; - - image->id = formats[i].id; - image->type = formats[i].type; - image->byte_order = formats[i].byte_order; - memcpy(image->guid, formats[i].guid, 16); - image->bits_per_pixel = formats[i].bpp; - image->format = formats[i].format; - image->num_planes = formats[i].num_planes; - image->depth = formats[i].depth; - image->red_mask = formats[i].red_mask; - image->green_mask = formats[i].green_mask; - image->blue_mask = formats[i].blue_mask; - image->y_sample_bits = formats[i].y_sample_bits; - image->u_sample_bits = formats[i].u_sample_bits; - image->v_sample_bits = formats[i].v_sample_bits; - image->horz_y_period = formats[i].vhorz_y_period; - image->horz_u_period = formats[i].vhorz_u_period; - image->horz_v_period = formats[i].vhorz_v_period; - image->vert_y_period = formats[i].vvert_y_period; - image->vert_u_period = formats[i].vvert_u_period; - image->vert_v_period = formats[i].vvert_v_period; - memcpy(image->component_order, formats[i].vcomp_order, 32); - image->scanline_order = formats[i].vscanline_order; - } - - free(reply); - return TRUE; -} - -static Bool -ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_screen_t *xscreen = xcb_aux_get_screen(conn, hostx_get_screen()); - int base_port_id = 0, i = 0, port_priv_offset = 0; - Bool is_ok = FALSE; - xcb_generic_error_t *e = NULL; - xcb_xv_adaptor_info_iterator_t it; - - EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE); - - EPHYR_LOG("enter\n"); - - { - xcb_xv_query_adaptors_cookie_t cookie = - xcb_xv_query_adaptors(conn, xscreen->root); - a_this->host_adaptors = xcb_xv_query_adaptors_reply(conn, cookie, &e); - if (e) { - free(e); - EPHYR_LOG_ERROR("failed to query host adaptors\n"); - goto out; - } - } - - if (a_this->host_adaptors) - a_this->num_adaptors = a_this->host_adaptors->num_adaptors; - if (a_this->num_adaptors <= 0) { - EPHYR_LOG_ERROR("failed to get number of host adaptors\n"); - goto out; - } - EPHYR_LOG("host has %d adaptors\n", a_this->num_adaptors); - /* - * copy what we can from adaptors into a_this->adaptors - */ - if (a_this->num_adaptors) { - a_this->adaptors = calloc(a_this->num_adaptors, - sizeof(KdVideoAdaptorRec)); - if (!a_this->adaptors) { - EPHYR_LOG_ERROR("failed to create internal adaptors\n"); - goto out; - } - } - - it = xcb_xv_query_adaptors_info_iterator(a_this->host_adaptors); - for (i = 0; i < a_this->num_adaptors; i++) { - xcb_xv_adaptor_info_t *cur_host_adaptor = it.data; - xcb_xv_format_t *format = xcb_xv_adaptor_info_formats(cur_host_adaptor); - int j = 0; - - a_this->adaptors[i].nPorts = cur_host_adaptor->num_ports; - if (a_this->adaptors[i].nPorts <= 0) { - EPHYR_LOG_ERROR("Could not find any port of adaptor %d\n", i); - continue; - } - a_this->adaptors[i].type = cur_host_adaptor->type; - a_this->adaptors[i].type |= XvWindowMask; - a_this->adaptors[i].flags = - VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT; - a_this->adaptors[i].name = - strndup(xcb_xv_adaptor_info_name(cur_host_adaptor), - cur_host_adaptor->name_size); - if (!a_this->adaptors[i].name) - a_this->adaptors[i].name = strdup("Xephyr Video Overlay"); - base_port_id = cur_host_adaptor->base_id; - if (base_port_id < 0) { - EPHYR_LOG_ERROR("failed to get port id for adaptor %d\n", i); - continue; - } - if (!s_base_port_id) - s_base_port_id = base_port_id; - - if (!translate_video_encodings(&a_this->adaptors[i], - cur_host_adaptor)) { - EPHYR_LOG_ERROR("failed to get encodings for port port id %d," - " adaptors %d\n", base_port_id, i); - continue; - } - - a_this->adaptors[i].nFormats = cur_host_adaptor->num_formats; - a_this->adaptors[i].pFormats = - calloc(cur_host_adaptor->num_formats, - sizeof(*a_this->adaptors[i].pFormats)); - for (j = 0; j < cur_host_adaptor->num_formats; j++) { - xcb_visualtype_t *visual = - xcb_aux_find_visual_by_id(xscreen, format[j].visual); - a_this->adaptors[i].pFormats[j].depth = format[j].depth; - a_this->adaptors[i].pFormats[j].class = visual->_class; - } - - a_this->adaptors[i].pPortPrivates = - calloc(a_this->adaptors[i].nPorts, - sizeof(DevUnion) + sizeof(EphyrPortPriv)); - port_priv_offset = a_this->adaptors[i].nPorts; - for (j = 0; j < a_this->adaptors[i].nPorts; j++) { - EphyrPortPriv *port_privs_base = - (EphyrPortPriv *) &a_this->adaptors[i]. - pPortPrivates[port_priv_offset]; - EphyrPortPriv *port_priv = &port_privs_base[j]; - - port_priv->port_number = base_port_id + j; - port_priv->current_adaptor = &a_this->adaptors[i]; - port_priv->xv_priv = a_this; - a_this->adaptors[i].pPortPrivates[j].ptr = port_priv; - } - - if (!translate_xv_attributes(&a_this->adaptors[i], cur_host_adaptor)) { - { - EPHYR_LOG_ERROR("failed to get port attribute " - "for adaptor %d\n", i); - continue; - } - } - - if (!translate_xv_image_formats(&a_this->adaptors[i], cur_host_adaptor)) { - EPHYR_LOG_ERROR("failed to get image formats " - "for adaptor %d\n", i); - continue; - } - - xcb_xv_adaptor_info_next(&it); - } - is_ok = TRUE; - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} - -static Bool -ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this) -{ - int i = 0; - xcb_xv_adaptor_info_iterator_t it; - - EPHYR_RETURN_VAL_IF_FAIL(a_this, FALSE); - - EPHYR_LOG("enter\n"); - - it = xcb_xv_query_adaptors_info_iterator(a_this->host_adaptors); - for (i = 0; i < a_this->num_adaptors; i++) { - xcb_xv_adaptor_info_t *cur_host_adaptor = it.data; - - a_this->adaptors[i].ReputImage = ephyrReputImage; - a_this->adaptors[i].StopVideo = ephyrStopVideo; - a_this->adaptors[i].SetPortAttribute = ephyrSetPortAttribute; - a_this->adaptors[i].GetPortAttribute = ephyrGetPortAttribute; - a_this->adaptors[i].QueryBestSize = ephyrQueryBestSize; - a_this->adaptors[i].QueryImageAttributes = ephyrQueryImageAttributes; - - if (adaptor_has_flags(cur_host_adaptor, - XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK)) - a_this->adaptors[i].PutImage = ephyrPutImage; - - if (adaptor_has_flags(cur_host_adaptor, - XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK)) - a_this->adaptors[i].PutVideo = ephyrPutVideo; - - if (adaptor_has_flags(cur_host_adaptor, - XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK)) - a_this->adaptors[i].GetVideo = ephyrGetVideo; - - if (adaptor_has_flags(cur_host_adaptor, - XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK)) - a_this->adaptors[i].PutStill = ephyrPutStill; - - if (adaptor_has_flags(cur_host_adaptor, - XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_OUTPUT_MASK)) - a_this->adaptors[i].GetStill = ephyrGetStill; - } - EPHYR_LOG("leave\n"); - return TRUE; -} - -static Bool -ephyrXVPrivRegisterAdaptors(EphyrXVPriv * a_this, ScreenPtr a_screen) -{ - Bool is_ok = FALSE; - - EPHYR_RETURN_VAL_IF_FAIL(a_this && a_screen, FALSE); - - EPHYR_LOG("enter\n"); - - if (!a_this->num_adaptors) - goto out; - - if (!KdXVScreenInit(a_screen, a_this->adaptors, a_this->num_adaptors)) { - EPHYR_LOG_ERROR("failed to register adaptors\n"); - goto out; - } - EPHYR_LOG("there are %d registered adaptors\n", a_this->num_adaptors); - is_ok = TRUE; - - out: - - EPHYR_LOG("leave\n"); - return is_ok; -} - -static Bool -ephyrXVPrivIsAttrValueValid(XvAttributePtr a_attrs, - int a_attrs_len, - const char *a_attr_name, - int a_attr_value, Bool *a_is_valid) -{ - int i = 0; - - EPHYR_RETURN_VAL_IF_FAIL(a_attrs && a_attr_name && a_is_valid, FALSE); - - for (i = 0; i < a_attrs_len; i++) { - if (a_attrs[i].name && strcmp(a_attrs[i].name, a_attr_name)) - continue; - if (a_attrs[i].min_value > a_attr_value || - a_attrs[i].max_value < a_attr_value) { - *a_is_valid = FALSE; - EPHYR_LOG_ERROR("attribute was not valid\n" - "value:%d. min:%d. max:%d\n", - a_attr_value, - a_attrs[i].min_value, a_attrs[i].max_value); - } - else { - *a_is_valid = TRUE; - } - return TRUE; - } - return FALSE; -} - -static Bool -ephyrXVPrivGetImageBufSize(int a_port_id, - int a_image_id, - unsigned short a_width, - unsigned short a_height, int *a_size) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_xv_query_image_attributes_cookie_t cookie; - xcb_xv_query_image_attributes_reply_t *reply; - Bool is_ok = FALSE; - - EPHYR_RETURN_VAL_IF_FAIL(a_size, FALSE); - - EPHYR_LOG("enter\n"); - - cookie = xcb_xv_query_image_attributes(conn, - a_port_id, a_image_id, - a_width, a_height); - reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL); - if (!reply) - goto out; - - *a_size = reply->data_size; - is_ok = TRUE; - - free(reply); - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} - -static Bool -ephyrXVPrivSaveImageToPortPriv(EphyrPortPriv * a_port_priv, - const unsigned char *a_image_buf, - int a_image_len) -{ - Bool is_ok = FALSE; - - EPHYR_LOG("enter\n"); - - if (a_port_priv->image_buf_size < a_image_len) { - unsigned char *buf = NULL; - - buf = realloc(a_port_priv->image_buf, a_image_len); - if (!buf) { - EPHYR_LOG_ERROR("failed to realloc image buffer\n"); - goto out; - } - a_port_priv->image_buf = buf; - a_port_priv->image_buf_size = a_image_len; - } - memmove(a_port_priv->image_buf, a_image_buf, a_image_len); - is_ok = TRUE; - - out: - return is_ok; - EPHYR_LOG("leave\n"); -} - -static void -ephyrStopVideo(KdScreenInfo * a_info, void *a_port_priv, Bool a_exit) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - EphyrPortPriv *port_priv = a_port_priv; - EphyrScrPriv *scrpriv = a_info->driver; - - EPHYR_RETURN_IF_FAIL(port_priv); - - EPHYR_LOG("enter\n"); - xcb_xv_stop_video(conn, port_priv->port_number, scrpriv->win); - EPHYR_LOG("leave\n"); -} - -static int -ephyrSetPortAttribute(KdScreenInfo * a_info, - Atom a_attr_name, int a_attr_value, void *a_port_priv) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - int res = Success, host_atom = 0; - EphyrPortPriv *port_priv = a_port_priv; - Bool is_attr_valid = FALSE; - - EPHYR_RETURN_VAL_IF_FAIL(port_priv, BadMatch); - EPHYR_RETURN_VAL_IF_FAIL(port_priv->current_adaptor, BadMatch); - EPHYR_RETURN_VAL_IF_FAIL(port_priv->current_adaptor->pAttributes, BadMatch); - EPHYR_RETURN_VAL_IF_FAIL(port_priv->current_adaptor->nAttributes, BadMatch); - EPHYR_RETURN_VAL_IF_FAIL(ValidAtom(a_attr_name), BadMatch); - - EPHYR_LOG("enter, portnum:%d, atomid:%d, attr_name:%s, attr_val:%d\n", - port_priv->port_number, - (int) a_attr_name, NameForAtom(a_attr_name), a_attr_value); - - if (!ephyrLocalAtomToHost(a_attr_name, &host_atom)) { - EPHYR_LOG_ERROR("failed to convert local atom to host atom\n"); - res = BadMatch; - goto out; - } - - if (!ephyrXVPrivIsAttrValueValid(port_priv->current_adaptor->pAttributes, - port_priv->current_adaptor->nAttributes, - NameForAtom(a_attr_name), - a_attr_value, &is_attr_valid)) { - EPHYR_LOG_ERROR("failed to validate attribute %s\n", - NameForAtom(a_attr_name)); - /* - res = BadMatch ; - goto out ; - */ - } - if (!is_attr_valid) { - EPHYR_LOG_ERROR("attribute %s is not valid\n", - NameForAtom(a_attr_name)); - /* - res = BadMatch ; - goto out ; - */ - } - - xcb_xv_set_port_attribute(conn, port_priv->port_number, - host_atom, a_attr_value); - xcb_flush(conn); - - res = Success; - out: - EPHYR_LOG("leave\n"); - return res; -} - -static int -ephyrGetPortAttribute(KdScreenInfo * a_screen_info, - Atom a_attr_name, int *a_attr_value, void *a_port_priv) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - int res = Success, host_atom = 0; - EphyrPortPriv *port_priv = a_port_priv; - xcb_generic_error_t *e; - xcb_xv_get_port_attribute_cookie_t cookie; - xcb_xv_get_port_attribute_reply_t *reply; - - EPHYR_RETURN_VAL_IF_FAIL(port_priv, BadMatch); - EPHYR_RETURN_VAL_IF_FAIL(ValidAtom(a_attr_name), BadMatch); - - EPHYR_LOG("enter, portnum:%d, atomid:%d, attr_name:%s\n", - port_priv->port_number, - (int) a_attr_name, NameForAtom(a_attr_name)); - - if (!ephyrLocalAtomToHost(a_attr_name, &host_atom)) { - EPHYR_LOG_ERROR("failed to convert local atom to host atom\n"); - res = BadMatch; - goto out; - } - - cookie = xcb_xv_get_port_attribute(conn, port_priv->port_number, host_atom); - reply = xcb_xv_get_port_attribute_reply(conn, cookie, &e); - if (e) { - EPHYR_LOG_ERROR ("XvGetPortAttribute() failed: %d \n", e->error_code); - free(e); - res = BadMatch; - goto out; - } - *a_attr_value = reply->value; - - free(reply); - - res = Success; - out: - EPHYR_LOG("leave\n"); - return res; -} - -static void -ephyrQueryBestSize(KdScreenInfo * a_info, - Bool a_motion, - short a_src_w, - short a_src_h, - short a_drw_w, - short a_drw_h, - unsigned int *a_prefered_w, - unsigned int *a_prefered_h, void *a_port_priv) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - EphyrPortPriv *port_priv = a_port_priv; - xcb_xv_query_best_size_cookie_t cookie = - xcb_xv_query_best_size(conn, - port_priv->port_number, - a_src_w, a_src_h, - a_drw_w, a_drw_h, - a_motion); - xcb_xv_query_best_size_reply_t *reply = - xcb_xv_query_best_size_reply(conn, cookie, NULL); - - EPHYR_LOG("enter: frame (%dx%d), drw (%dx%d)\n", - a_src_w, a_src_h, a_drw_w, a_drw_h); - - if (!reply) { - EPHYR_LOG_ERROR ("XvQueryBestSize() failed\n"); - return; - } - *a_prefered_w = reply->actual_width; - *a_prefered_h = reply->actual_height; - EPHYR_LOG("actual (%dx%d)\n", *a_prefered_w, *a_prefered_h); - free(reply); - - EPHYR_LOG("leave\n"); -} - - -static Bool -ephyrHostXVPutImage(KdScreenInfo * a_info, - EphyrPortPriv *port_priv, - int a_image_id, - int a_drw_x, - int a_drw_y, - int a_drw_w, - int a_drw_h, - int a_src_x, - int a_src_y, - int a_src_w, - int a_src_h, - int a_image_width, - int a_image_height, - unsigned char *a_buf, - BoxPtr a_clip_rects, int a_clip_rect_nums) -{ - EphyrScrPriv *scrpriv = a_info->driver; - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_gcontext_t gc; - Bool is_ok = TRUE; - xcb_rectangle_t *rects = NULL; - int data_len, width, height; - xcb_xv_query_image_attributes_cookie_t image_attr_cookie; - xcb_xv_query_image_attributes_reply_t *image_attr_reply; - - EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE); - - EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums); - - image_attr_cookie = xcb_xv_query_image_attributes(conn, - port_priv->port_number, - a_image_id, - a_image_width, - a_image_height); - image_attr_reply = xcb_xv_query_image_attributes_reply(conn, - image_attr_cookie, - NULL); - if (!image_attr_reply) - goto out; - data_len = image_attr_reply->data_size; - width = image_attr_reply->width; - height = image_attr_reply->height; - free(image_attr_reply); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, scrpriv->win, 0, NULL); - - if (a_clip_rect_nums) { - int i = 0; - rects = calloc(a_clip_rect_nums, sizeof(xcb_rectangle_t)); - for (i=0; i < a_clip_rect_nums; i++) { - rects[i].x = a_clip_rects[i].x1; - rects[i].y = a_clip_rects[i].y1; - rects[i].width = a_clip_rects[i].x2 - a_clip_rects[i].x1; - rects[i].height = a_clip_rects[i].y2 - a_clip_rects[i].y1; - EPHYR_LOG("(x,y,w,h): (%d,%d,%d,%d)\n", - rects[i].x, rects[i].y, rects[i].width, rects[i].height); - } - xcb_set_clip_rectangles(conn, - XCB_CLIP_ORDERING_YX_BANDED, - gc, - 0, - 0, - a_clip_rect_nums, - rects); - free(rects); - } - xcb_xv_put_image(conn, - port_priv->port_number, - scrpriv->win, - gc, - a_image_id, - a_src_x, a_src_y, a_src_w, a_src_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h, - width, height, - data_len, a_buf); - xcb_free_gc(conn, gc); - - is_ok = TRUE; - -out: - EPHYR_LOG("leave\n"); - return is_ok; -} - -static int -ephyrPutImage(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_src_x, - short a_src_y, - short a_drw_x, - short a_drw_y, - short a_src_w, - short a_src_h, - short a_drw_w, - short a_drw_h, - int a_id, - unsigned char *a_buf, - short a_width, - short a_height, - Bool a_sync, RegionPtr a_clipping_region, void *a_port_priv) -{ - EphyrPortPriv *port_priv = a_port_priv; - Bool is_ok = FALSE; - int result = BadImplementation, image_size = 0; - - EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue); - EPHYR_RETURN_VAL_IF_FAIL(a_drawable, BadValue); - - EPHYR_LOG("enter\n"); - - if (!ephyrHostXVPutImage(a_info, port_priv, - a_id, - a_drw_x, a_drw_y, a_drw_w, a_drw_h, - a_src_x, a_src_y, a_src_w, a_src_h, - a_width, a_height, a_buf, - RegionRects(a_clipping_region), - RegionNumRects(a_clipping_region))) { - EPHYR_LOG_ERROR("EphyrHostXVPutImage() failed\n"); - goto out; - } - - /* - * Now save the image so that we can resend it to host it - * later, in ReputImage. - */ - if (!ephyrXVPrivGetImageBufSize(port_priv->port_number, - a_id, a_width, a_height, &image_size)) { - EPHYR_LOG_ERROR("failed to get image size\n"); - /*this is a minor error so we won't get bail out abruptly */ - is_ok = FALSE; - } - else { - is_ok = TRUE; - } - if (is_ok) { - if (!ephyrXVPrivSaveImageToPortPriv(port_priv, a_buf, image_size)) { - is_ok = FALSE; - } - else { - port_priv->image_id = a_id; - port_priv->drw_x = a_drw_x; - port_priv->drw_y = a_drw_y; - port_priv->drw_w = a_drw_w; - port_priv->drw_h = a_drw_h; - port_priv->src_x = a_src_x; - port_priv->src_y = a_src_y; - port_priv->src_w = a_src_w; - port_priv->src_h = a_src_h; - port_priv->image_width = a_width; - port_priv->image_height = a_height; - } - } - if (!is_ok) { - if (port_priv->image_buf) { - free(port_priv->image_buf); - port_priv->image_buf = NULL; - port_priv->image_buf_size = 0; - } - } - - result = Success; - - out: - EPHYR_LOG("leave\n"); - return result; -} - -static int -ephyrReputImage(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_drw_x, - short a_drw_y, RegionPtr a_clipping_region, void *a_port_priv) -{ - EphyrPortPriv *port_priv = a_port_priv; - int result = BadImplementation; - - EPHYR_RETURN_VAL_IF_FAIL(a_info->pScreen, FALSE); - EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue); - - EPHYR_LOG("enter\n"); - - if (!port_priv->image_buf_size || !port_priv->image_buf) { - EPHYR_LOG_ERROR("has null image buf in cache\n"); - goto out; - } - if (!ephyrHostXVPutImage(a_info, - port_priv, - port_priv->image_id, - a_drw_x, a_drw_y, - port_priv->drw_w, port_priv->drw_h, - port_priv->src_x, port_priv->src_y, - port_priv->src_w, port_priv->src_h, - port_priv->image_width, port_priv->image_height, - port_priv->image_buf, - RegionRects(a_clipping_region), - RegionNumRects(a_clipping_region))) { - EPHYR_LOG_ERROR("ephyrHostXVPutImage() failed\n"); - goto out; - } - - result = Success; - - out: - EPHYR_LOG("leave\n"); - return result; -} - -static int -ephyrPutVideo(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clipping_region, void *a_port_priv) -{ - EphyrScrPriv *scrpriv = a_info->driver; - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_gcontext_t gc; - EphyrPortPriv *port_priv = a_port_priv; - - EPHYR_RETURN_VAL_IF_FAIL(a_info->pScreen, BadValue); - EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue); - - EPHYR_LOG("enter\n"); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, scrpriv->win, 0, NULL); - xcb_xv_put_video(conn, port_priv->port_number, - scrpriv->win, gc, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h); - xcb_free_gc(conn, gc); - - EPHYR_LOG("leave\n"); - return Success; -} - -static int -ephyrGetVideo(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clipping_region, void *a_port_priv) -{ - EphyrScrPriv *scrpriv = a_info->driver; - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_gcontext_t gc; - EphyrPortPriv *port_priv = a_port_priv; - - EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue); - EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue); - - EPHYR_LOG("enter\n"); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, scrpriv->win, 0, NULL); - xcb_xv_get_video(conn, port_priv->port_number, - scrpriv->win, gc, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h); - - xcb_free_gc(conn, gc); - - EPHYR_LOG("leave\n"); - return Success; -} - -static int -ephyrPutStill(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clipping_region, void *a_port_priv) -{ - EphyrScrPriv *scrpriv = a_info->driver; - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_gcontext_t gc; - EphyrPortPriv *port_priv = a_port_priv; - - EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue); - EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue); - - EPHYR_LOG("enter\n"); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, scrpriv->win, 0, NULL); - xcb_xv_put_still(conn, port_priv->port_number, - scrpriv->win, gc, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h); - xcb_free_gc(conn, gc); - - EPHYR_LOG("leave\n"); - return Success; -} - -static int -ephyrGetStill(KdScreenInfo * a_info, - DrawablePtr a_drawable, - short a_vid_x, short a_vid_y, - short a_drw_x, short a_drw_y, - short a_vid_w, short a_vid_h, - short a_drw_w, short a_drw_h, - RegionPtr a_clipping_region, void *a_port_priv) -{ - EphyrScrPriv *scrpriv = a_info->driver; - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_gcontext_t gc; - EphyrPortPriv *port_priv = a_port_priv; - - EPHYR_RETURN_VAL_IF_FAIL(a_info && a_info->pScreen, BadValue); - EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue); - - EPHYR_LOG("enter\n"); - - gc = xcb_generate_id(conn); - xcb_create_gc(conn, gc, scrpriv->win, 0, NULL); - xcb_xv_get_still(conn, port_priv->port_number, - scrpriv->win, gc, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h); - xcb_free_gc(conn, gc); - - EPHYR_LOG("leave\n"); - return Success; -} - -static int -ephyrQueryImageAttributes(KdScreenInfo * a_info, - int a_id, - unsigned short *a_w, - unsigned short *a_h, int *a_pitches, int *a_offsets) -{ - xcb_connection_t *conn = hostx_get_xcbconn(); - xcb_xv_query_image_attributes_cookie_t cookie; - xcb_xv_query_image_attributes_reply_t *reply; - int image_size = 0; - - EPHYR_RETURN_VAL_IF_FAIL(a_w && a_h, FALSE); - - EPHYR_LOG("enter: dim (%dx%d), pitches: %p, offsets: %p\n", - *a_w, *a_h, a_pitches, a_offsets); - - cookie = xcb_xv_query_image_attributes(conn, - s_base_port_id, a_id, - *a_w, *a_h); - reply = xcb_xv_query_image_attributes_reply(conn, cookie, NULL); - if (!reply) - goto out; - - *a_w = reply->width; - *a_h = reply->height; - if (a_pitches && a_offsets) { - memcpy(a_pitches, xcb_xv_query_image_attributes_pitches(reply), - reply->num_planes << 2); - memcpy(a_offsets, xcb_xv_query_image_attributes_offsets(reply), - reply->num_planes << 2); - } - image_size = reply->data_size; - - free(reply); - - EPHYR_LOG("image size: %d, dim (%dx%d)\n", image_size, *a_w, *a_h); - - out: - EPHYR_LOG("leave\n"); - return image_size; -} diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c deleted file mode 100644 index a5b2e344e..000000000 --- a/hw/kdrive/ephyr/hostx.c +++ /dev/null @@ -1,1666 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2004 Nokia - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Nokia not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Nokia makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif - -#include "hostx.h" -#include "input.h" - -#include -#include -#include -#include /* for memset */ -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef GLAMOR -#include -#include "glamor.h" -#include "ephyr_glamor_glx.h" -#endif -#include "ephyrlog.h" -#include "ephyr.h" - -struct EphyrHostXVars { - char *server_dpy_name; - xcb_connection_t *conn; - int screen; - xcb_visualtype_t *visual; - Window winroot; - xcb_gcontext_t gc; - xcb_render_pictformat_t argb_format; - xcb_cursor_t empty_cursor; - xcb_generic_event_t *saved_event; - int depth; - Bool use_sw_cursor; - Bool use_fullscreen; - Bool have_shm; - Bool have_shm_fd_passing; - - int n_screens; - KdScreenInfo **screens; - - long damage_debug_msec; - Bool size_set_from_configure; -}; - -/* memset ( missing> ) instead of below */ -/*static EphyrHostXVars HostX = { "?", 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};*/ -static EphyrHostXVars HostX; - -static int HostXWantDamageDebug = 0; - -extern Bool EphyrWantResize; - -char *ephyrResName = NULL; -int ephyrResNameFromCmd = 0; -char *ephyrTitle = NULL; -Bool ephyr_glamor = FALSE; -extern Bool ephyr_glamor_skip_present; - -Bool -hostx_has_extension(xcb_extension_t *extension) -{ - const xcb_query_extension_reply_t *rep; - - rep = xcb_get_extension_data(HostX.conn, extension); - - return rep && rep->present; -} - -static void - hostx_set_fullscreen_hint(void); - -#define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth) - -int -hostx_want_screen_geometry(KdScreenInfo *screen, int *width, int *height, int *x, int *y) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv && (scrpriv->win_pre_existing != None || - scrpriv->output != NULL || - HostX.use_fullscreen == TRUE)) { - *x = scrpriv->win_x; - *y = scrpriv->win_y; - *width = scrpriv->win_width; - *height = scrpriv->win_height; - return 1; - } - - return 0; -} - -void -hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry, const char *output) -{ - EphyrScrPriv *scrpriv = screen->driver; - int index = HostX.n_screens; - - HostX.n_screens += 1; - HostX.screens = reallocarray(HostX.screens, - HostX.n_screens, sizeof(HostX.screens[0])); - HostX.screens[index] = screen; - - scrpriv->screen = screen; - scrpriv->win_pre_existing = win_id; - scrpriv->win_explicit_position = use_geometry; - scrpriv->output = output; -} - -void -hostx_set_display_name(char *name) -{ - HostX.server_dpy_name = strdup(name); -} - -void -hostx_set_screen_number(KdScreenInfo *screen, int number) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv) { - scrpriv->mynum = number; - hostx_set_win_title(screen, ""); - } -} - -void -hostx_set_win_title(KdScreenInfo *screen, const char *extra_text) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (!scrpriv) - return; - - if (ephyrTitle) { - xcb_icccm_set_wm_name(HostX.conn, - scrpriv->win, - XCB_ATOM_STRING, - 8, - strlen(ephyrTitle), - ephyrTitle); - } else { -#define BUF_LEN 256 - char buf[BUF_LEN + 1]; - - memset(buf, 0, BUF_LEN + 1); - snprintf(buf, BUF_LEN, "Xephyr on %s.%d %s", - HostX.server_dpy_name ? HostX.server_dpy_name : ":0", - scrpriv->mynum, (extra_text != NULL) ? extra_text : ""); - - xcb_icccm_set_wm_name(HostX.conn, - scrpriv->win, - XCB_ATOM_STRING, - 8, - strlen(buf), - buf); - xcb_flush(HostX.conn); - } -} - -int -hostx_want_host_cursor(void) -{ - return !HostX.use_sw_cursor; -} - -void -hostx_use_sw_cursor(void) -{ - HostX.use_sw_cursor = TRUE; -} - -xcb_cursor_t -hostx_get_empty_cursor(void) -{ - return HostX.empty_cursor; -} - -int -hostx_want_preexisting_window(KdScreenInfo *screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (scrpriv && scrpriv->win_pre_existing) { - return 1; - } - else { - return 0; - } -} - -void -hostx_get_output_geometry(const char *output, - int *x, int *y, - int *width, int *height) -{ - int i, name_len = 0, output_found = FALSE; - char *name = NULL; - xcb_generic_error_t *error; - xcb_randr_query_version_cookie_t version_c; - xcb_randr_query_version_reply_t *version_r; - xcb_randr_get_screen_resources_cookie_t screen_resources_c; - xcb_randr_get_screen_resources_reply_t *screen_resources_r; - xcb_randr_output_t *randr_outputs; - xcb_randr_get_output_info_cookie_t output_info_c; - xcb_randr_get_output_info_reply_t *output_info_r; - xcb_randr_get_crtc_info_cookie_t crtc_info_c; - xcb_randr_get_crtc_info_reply_t *crtc_info_r; - - /* First of all, check for extension */ - if (!hostx_has_extension(&xcb_randr_id)) - { - fprintf(stderr, "\nHost X server does not support RANDR extension (or it's disabled).\n"); - exit(1); - } - - /* Check RandR version */ - version_c = xcb_randr_query_version(HostX.conn, 1, 2); - version_r = xcb_randr_query_version_reply(HostX.conn, - version_c, - &error); - - if (error != NULL || version_r == NULL) - { - fprintf(stderr, "\nFailed to get RandR version supported by host X server.\n"); - exit(1); - } - else if (version_r->major_version < 1 || version_r->minor_version < 2) - { - free(version_r); - fprintf(stderr, "\nHost X server doesn't support RandR 1.2, needed for -output usage.\n"); - exit(1); - } - - free(version_r); - - /* Get list of outputs from screen resources */ - screen_resources_c = xcb_randr_get_screen_resources(HostX.conn, - HostX.winroot); - screen_resources_r = xcb_randr_get_screen_resources_reply(HostX.conn, - screen_resources_c, - NULL); - randr_outputs = xcb_randr_get_screen_resources_outputs(screen_resources_r); - - for (i = 0; !output_found && i < screen_resources_r->num_outputs; i++) - { - /* Get info on the output */ - output_info_c = xcb_randr_get_output_info(HostX.conn, - randr_outputs[i], - XCB_CURRENT_TIME); - output_info_r = xcb_randr_get_output_info_reply(HostX.conn, - output_info_c, - NULL); - - /* Get output name */ - name_len = xcb_randr_get_output_info_name_length(output_info_r); - name = malloc(name_len + 1); - strncpy(name, (char*)xcb_randr_get_output_info_name(output_info_r), name_len); - name[name_len] = '\0'; - - if (!strcmp(name, output)) - { - output_found = TRUE; - - /* Check if output is connected */ - if (output_info_r->crtc == XCB_NONE) - { - free(name); - free(output_info_r); - free(screen_resources_r); - fprintf(stderr, "\nOutput %s is currently disabled (or not connected).\n", output); - exit(1); - } - - /* Get CRTC from output info */ - crtc_info_c = xcb_randr_get_crtc_info(HostX.conn, - output_info_r->crtc, - XCB_CURRENT_TIME); - crtc_info_r = xcb_randr_get_crtc_info_reply(HostX.conn, - crtc_info_c, - NULL); - - /* Get CRTC geometry */ - *x = crtc_info_r->x; - *y = crtc_info_r->y; - *width = crtc_info_r->width; - *height = crtc_info_r->height; - - free(crtc_info_r); - } - - free(name); - free(output_info_r); - } - - free(screen_resources_r); - - if (!output_found) - { - fprintf(stderr, "\nOutput %s not available in host X server.\n", output); - exit(1); - } -} - -void -hostx_use_fullscreen(void) -{ - HostX.use_fullscreen = TRUE; -} - -int -hostx_want_fullscreen(void) -{ - return HostX.use_fullscreen; -} - -static xcb_intern_atom_cookie_t cookie_WINDOW_STATE, - cookie_WINDOW_STATE_FULLSCREEN; - -static void -hostx_set_fullscreen_hint(void) -{ - xcb_atom_t atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN; - int index; - xcb_intern_atom_reply_t *reply; - - reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE, NULL); - atom_WINDOW_STATE = reply->atom; - free(reply); - - reply = xcb_intern_atom_reply(HostX.conn, cookie_WINDOW_STATE_FULLSCREEN, - NULL); - atom_WINDOW_STATE_FULLSCREEN = reply->atom; - free(reply); - - for (index = 0; index < HostX.n_screens; index++) { - EphyrScrPriv *scrpriv = HostX.screens[index]->driver; - xcb_change_property(HostX.conn, - PropModeReplace, - scrpriv->win, - atom_WINDOW_STATE, - XCB_ATOM_ATOM, - 32, - 1, - &atom_WINDOW_STATE_FULLSCREEN); - } -} - -static void -hostx_toggle_damage_debug(void) -{ - HostXWantDamageDebug ^= 1; -} - -void -hostx_handle_signal(int signum) -{ - hostx_toggle_damage_debug(); - EPHYR_DBG("Signal caught. Damage Debug:%i\n", HostXWantDamageDebug); -} - -void -hostx_use_resname(char *name, int fromcmd) -{ - ephyrResName = name; - ephyrResNameFromCmd = fromcmd; -} - -void -hostx_set_title(char *title) -{ - ephyrTitle = title; -} - -#ifdef __SUNPRO_C -/* prevent "Function has no return statement" error for x_io_error_handler */ -#pragma does_not_return(exit) -#endif - -static void -hostx_init_shm(void) -{ - /* Try to get share memory ximages for a little bit more speed */ - if (!hostx_has_extension(&xcb_shm_id) || getenv("XEPHYR_NO_SHM")) { - HostX.have_shm = FALSE; - } else { - xcb_generic_error_t *error = NULL; - xcb_shm_query_version_cookie_t cookie; - xcb_shm_query_version_reply_t *reply; - - HostX.have_shm = TRUE; - HostX.have_shm_fd_passing = FALSE; - cookie = xcb_shm_query_version(HostX.conn); - reply = xcb_shm_query_version_reply(HostX.conn, cookie, &error); - if (reply) { - HostX.have_shm_fd_passing = - (reply->major_version == 1 && reply->minor_version >= 2) || - reply->major_version > 1; - free(reply); - } - free(error); - } -} - -static Bool -hostx_create_shm_segment(xcb_shm_segment_info_t *shminfo, size_t size) -{ - shminfo->shmaddr = NULL; - - if (HostX.have_shm_fd_passing) { - xcb_generic_error_t *error = NULL; - xcb_shm_create_segment_cookie_t cookie; - xcb_shm_create_segment_reply_t *reply; - - shminfo->shmseg = xcb_generate_id(HostX.conn); - cookie = xcb_shm_create_segment(HostX.conn, shminfo->shmseg, size, TRUE); - reply = xcb_shm_create_segment_reply(HostX.conn, cookie, &error); - if (reply) { - int *fds = reply->nfd == 1 ? - xcb_shm_create_segment_reply_fds(HostX.conn, reply) : NULL; - if (fds) { - shminfo->shmaddr = - (uint8_t *)mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fds[0], 0); - close(fds[0]); - if (shminfo->shmaddr == MAP_FAILED) - shminfo->shmaddr = NULL; - } - if (!shminfo->shmaddr) - xcb_shm_detach(HostX.conn, shminfo->shmseg); - - free(reply); - } - free(error); - } else { - shminfo->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT|0666); - if (shminfo->shmid != -1) { - shminfo->shmaddr = shmat(shminfo->shmid, 0, 0); - if (shminfo->shmaddr == (void *)-1) { - shminfo->shmaddr = NULL; - } else { - xcb_generic_error_t *error = NULL; - xcb_void_cookie_t cookie; - - shmctl(shminfo->shmid, IPC_RMID, 0); - - shminfo->shmseg = xcb_generate_id(HostX.conn); - cookie = xcb_shm_attach_checked(HostX.conn, shminfo->shmseg, shminfo->shmid, TRUE); - error = xcb_request_check(HostX.conn, cookie); - - if (error) { - free(error); - shmdt(shminfo->shmaddr); - shminfo->shmaddr = NULL; - } - } - } - } - - return shminfo->shmaddr != NULL; -} - -static void -hostx_destroy_shm_segment(xcb_shm_segment_info_t *shminfo, size_t size) -{ - xcb_shm_detach(HostX.conn, shminfo->shmseg); - - if (HostX.have_shm_fd_passing) - munmap(shminfo->shmaddr, size); - else - shmdt(shminfo->shmaddr); - - shminfo->shmaddr = NULL; -} - -int -hostx_init(void) -{ - uint32_t attrs[2]; - uint32_t attr_mask = 0; - xcb_pixmap_t cursor_pxm; - xcb_gcontext_t cursor_gc; - uint16_t red, green, blue; - uint32_t pixel; - int index; - char *tmpstr; - char *class_hint; - size_t class_len; - xcb_screen_t *xscreen; - xcb_rectangle_t rect = { 0, 0, 1, 1 }; - - attrs[0] = - XCB_EVENT_MASK_BUTTON_PRESS - | XCB_EVENT_MASK_BUTTON_RELEASE - | XCB_EVENT_MASK_POINTER_MOTION - | XCB_EVENT_MASK_KEY_PRESS - | XCB_EVENT_MASK_KEY_RELEASE - | XCB_EVENT_MASK_EXPOSURE - | XCB_EVENT_MASK_STRUCTURE_NOTIFY; - attr_mask |= XCB_CW_EVENT_MASK; - - EPHYR_DBG("mark"); -#ifdef GLAMOR - if (ephyr_glamor) - HostX.conn = ephyr_glamor_connect(); - else -#endif - HostX.conn = xcb_connect(NULL, &HostX.screen); - if (!HostX.conn || xcb_connection_has_error(HostX.conn)) { - fprintf(stderr, "\nXephyr cannot open host display. Is DISPLAY set?\n"); - exit(1); - } - - xscreen = xcb_aux_get_screen(HostX.conn, HostX.screen); - HostX.winroot = xscreen->root; - HostX.gc = xcb_generate_id(HostX.conn); - HostX.depth = xscreen->root_depth; -#ifdef GLAMOR - if (ephyr_glamor) { - HostX.visual = ephyr_glamor_get_visual(); - if (HostX.visual->visual_id != xscreen->root_visual) { - attrs[1] = xcb_generate_id(HostX.conn); - attr_mask |= XCB_CW_COLORMAP; - xcb_create_colormap(HostX.conn, - XCB_COLORMAP_ALLOC_NONE, - attrs[1], - HostX.winroot, - HostX.visual->visual_id); - } - } else -#endif - HostX.visual = xcb_aux_find_visual_by_id(xscreen,xscreen->root_visual); - - xcb_create_gc(HostX.conn, HostX.gc, HostX.winroot, 0, NULL); - cookie_WINDOW_STATE = xcb_intern_atom(HostX.conn, FALSE, - strlen("_NET_WM_STATE"), - "_NET_WM_STATE"); - cookie_WINDOW_STATE_FULLSCREEN = - xcb_intern_atom(HostX.conn, FALSE, - strlen("_NET_WM_STATE_FULLSCREEN"), - "_NET_WM_STATE_FULLSCREEN"); - - for (index = 0; index < HostX.n_screens; index++) { - KdScreenInfo *screen = HostX.screens[index]; - EphyrScrPriv *scrpriv = screen->driver; - - scrpriv->win = xcb_generate_id(HostX.conn); - scrpriv->server_depth = HostX.depth; - scrpriv->ximg = NULL; - scrpriv->win_x = 0; - scrpriv->win_y = 0; - - if (scrpriv->win_pre_existing != XCB_WINDOW_NONE) { - xcb_get_geometry_reply_t *prewin_geom; - xcb_get_geometry_cookie_t cookie; - xcb_generic_error_t *e = NULL; - - /* Get screen size from existing window */ - cookie = xcb_get_geometry(HostX.conn, - scrpriv->win_pre_existing); - prewin_geom = xcb_get_geometry_reply(HostX.conn, cookie, &e); - - if (e) { - free(e); - free(prewin_geom); - fprintf (stderr, "\nXephyr -parent window' does not exist!\n"); - exit (1); - } - - scrpriv->win_width = prewin_geom->width; - scrpriv->win_height = prewin_geom->height; - - free(prewin_geom); - - xcb_create_window(HostX.conn, - XCB_COPY_FROM_PARENT, - scrpriv->win, - scrpriv->win_pre_existing, - 0,0, - scrpriv->win_width, - scrpriv->win_height, - 0, - XCB_WINDOW_CLASS_COPY_FROM_PARENT, - HostX.visual->visual_id, - attr_mask, - attrs); - } - else { - xcb_create_window(HostX.conn, - XCB_COPY_FROM_PARENT, - scrpriv->win, - HostX.winroot, - 0,0,100,100, /* will resize */ - 0, - XCB_WINDOW_CLASS_COPY_FROM_PARENT, - HostX.visual->visual_id, - attr_mask, - attrs); - - hostx_set_win_title(screen, - "(ctrl+shift grabs mouse and keyboard)"); - - if (HostX.use_fullscreen) { - scrpriv->win_width = xscreen->width_in_pixels; - scrpriv->win_height = xscreen->height_in_pixels; - - hostx_set_fullscreen_hint(); - } - else if (scrpriv->output) { - hostx_get_output_geometry(scrpriv->output, - &scrpriv->win_x, - &scrpriv->win_y, - &scrpriv->win_width, - &scrpriv->win_height); - - HostX.use_fullscreen = TRUE; - hostx_set_fullscreen_hint(); - } - - - tmpstr = getenv("RESOURCE_NAME"); - if (tmpstr && (!ephyrResNameFromCmd)) - ephyrResName = tmpstr; - class_len = strlen(ephyrResName) + 1 + strlen("Xephyr") + 1; - class_hint = malloc(class_len); - if (class_hint) { - strcpy(class_hint, ephyrResName); - strcpy(class_hint + strlen(ephyrResName) + 1, "Xephyr"); - xcb_change_property(HostX.conn, - XCB_PROP_MODE_REPLACE, - scrpriv->win, - XCB_ATOM_WM_CLASS, - XCB_ATOM_STRING, - 8, - class_len, - class_hint); - free(class_hint); - } - } - } - - if (!xcb_aux_parse_color((char*)"red", &red, &green, &blue)) { - xcb_lookup_color_cookie_t c = - xcb_lookup_color(HostX.conn, xscreen->default_colormap, 3, "red"); - xcb_lookup_color_reply_t *reply = - xcb_lookup_color_reply(HostX.conn, c, NULL); - red = reply->exact_red; - green = reply->exact_green; - blue = reply->exact_blue; - free(reply); - } - - { - xcb_alloc_color_cookie_t c = xcb_alloc_color(HostX.conn, - xscreen->default_colormap, - red, green, blue); - xcb_alloc_color_reply_t *r = xcb_alloc_color_reply(HostX.conn, c, NULL); - red = r->red; - green = r->green; - blue = r->blue; - pixel = r->pixel; - free(r); - } - - xcb_change_gc(HostX.conn, HostX.gc, XCB_GC_FOREGROUND, &pixel); - - cursor_pxm = xcb_generate_id(HostX.conn); - xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1); - cursor_gc = xcb_generate_id(HostX.conn); - pixel = 0; - xcb_create_gc(HostX.conn, cursor_gc, cursor_pxm, - XCB_GC_FOREGROUND, &pixel); - xcb_poly_fill_rectangle(HostX.conn, cursor_pxm, cursor_gc, 1, &rect); - xcb_free_gc(HostX.conn, cursor_gc); - HostX.empty_cursor = xcb_generate_id(HostX.conn); - xcb_create_cursor(HostX.conn, - HostX.empty_cursor, - cursor_pxm, cursor_pxm, - 0,0,0, - 0,0,0, - 1,1); - xcb_free_pixmap(HostX.conn, cursor_pxm); - if (!hostx_want_host_cursor ()) { - CursorVisible = TRUE; - /* Ditch the cursor, we provide our 'own' */ - for (index = 0; index < HostX.n_screens; index++) { - KdScreenInfo *screen = HostX.screens[index]; - EphyrScrPriv *scrpriv = screen->driver; - - xcb_change_window_attributes(HostX.conn, - scrpriv->win, - XCB_CW_CURSOR, - &HostX.empty_cursor); - } - } - - hostx_init_shm(); - if (HostX.have_shm) { - /* Really really check we have shm - better way ?*/ - xcb_shm_segment_info_t shminfo; - if (!hostx_create_shm_segment(&shminfo, 1)) { - fprintf(stderr, "\nXephyr unable to use SHM XImages\n"); - HostX.have_shm = FALSE; - } else { - hostx_destroy_shm_segment(&shminfo, 1); - } - } else { - fprintf(stderr, "\nXephyr unable to use SHM XImages\n"); - } - - xcb_flush(HostX.conn); - - /* Setup the pause time between paints when debugging updates */ - - HostX.damage_debug_msec = 20000; /* 1/50 th of a second */ - - if (getenv("XEPHYR_PAUSE")) { - HostX.damage_debug_msec = strtol(getenv("XEPHYR_PAUSE"), NULL, 0); - EPHYR_DBG("pause is %li\n", HostX.damage_debug_msec); - } - - return 1; -} - -int -hostx_get_depth(void) -{ - return HostX.depth; -} - -int -hostx_get_server_depth(KdScreenInfo *screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - - return scrpriv ? scrpriv->server_depth : 0; -} - -int -hostx_get_bpp(KdScreenInfo *screen) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (!scrpriv) - return 0; - - if (host_depth_matches_server(scrpriv)) - return HostX.visual->bits_per_rgb_value; - else - return scrpriv->server_depth; /*XXX correct ?*/ -} - -void -hostx_get_visual_masks(KdScreenInfo *screen, - CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk) -{ - EphyrScrPriv *scrpriv = screen->driver; - - if (!scrpriv) - return; - - if (host_depth_matches_server(scrpriv)) { - *rmsk = HostX.visual->red_mask; - *gmsk = HostX.visual->green_mask; - *bmsk = HostX.visual->blue_mask; - } - else if (scrpriv->server_depth == 16) { - /* Assume 16bpp 565 */ - *rmsk = 0xf800; - *gmsk = 0x07e0; - *bmsk = 0x001f; - } - else { - *rmsk = 0x0; - *gmsk = 0x0; - *bmsk = 0x0; - } -} - -static int -hostx_calculate_color_shift(unsigned long mask) -{ - int shift = 1; - - /* count # of bits in mask */ - while ((mask = (mask >> 1))) - shift++; - /* cmap entry is an unsigned char so adjust it by size of that */ - shift = shift - sizeof(unsigned char) * 8; - if (shift < 0) - shift = 0; - return shift; -} - -void -hostx_set_cmap_entry(ScreenPtr pScreen, unsigned char idx, - unsigned char r, unsigned char g, unsigned char b) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = screen->driver; -/* need to calculate the shifts for RGB because server could be BGR. */ -/* XXX Not sure if this is correct for 8 on 16, but this works for 8 on 24.*/ - static int rshift, bshift, gshift = 0; - static int first_time = 1; - - if (first_time) { - first_time = 0; - rshift = hostx_calculate_color_shift(HostX.visual->red_mask); - gshift = hostx_calculate_color_shift(HostX.visual->green_mask); - bshift = hostx_calculate_color_shift(HostX.visual->blue_mask); - } - scrpriv->cmap[idx] = ((r << rshift) & HostX.visual->red_mask) | - ((g << gshift) & HostX.visual->green_mask) | - ((b << bshift) & HostX.visual->blue_mask); -} - -/** - * hostx_screen_init creates the XImage that will contain the front buffer of - * the ephyr screen, and possibly offscreen memory. - * - * @param width width of the screen - * @param height height of the screen - * @param buffer_height height of the rectangle to be allocated. - * - * hostx_screen_init() creates an XImage, using MIT-SHM if it's available. - * buffer_height can be used to create a larger offscreen buffer, which is used - * by fakexa for storing offscreen pixmap data. - */ -void * -hostx_screen_init(KdScreenInfo *screen, - int x, int y, - int width, int height, int buffer_height, - int *bytes_per_line, int *bits_per_pixel) -{ - EphyrScrPriv *scrpriv = screen->driver; - Bool shm_success = FALSE; - - if (!scrpriv) { - fprintf(stderr, "%s: Error in accessing hostx data\n", __func__); - exit(1); - } - - EPHYR_DBG("host_screen=%p x=%d, y=%d, wxh=%dx%d, buffer_height=%d", - screen, x, y, width, height, buffer_height); - - if (scrpriv->ximg != NULL) { - /* Free up the image data if previously used - * i.ie called by server reset - */ - - if (HostX.have_shm) { - xcb_image_destroy(scrpriv->ximg); - hostx_destroy_shm_segment(&scrpriv->shminfo, scrpriv->shmsize); - } - else { - free(scrpriv->ximg->data); - scrpriv->ximg->data = NULL; - - xcb_image_destroy(scrpriv->ximg); - } - } - - if (!ephyr_glamor && HostX.have_shm) { - scrpriv->ximg = xcb_image_create_native(HostX.conn, - width, - buffer_height, - XCB_IMAGE_FORMAT_Z_PIXMAP, - HostX.depth, - NULL, - ~0, - NULL); - - scrpriv->shmsize = scrpriv->ximg->stride * buffer_height; - if (!hostx_create_shm_segment(&scrpriv->shminfo, - scrpriv->shmsize)) { - EPHYR_DBG - ("Can't create SHM Segment, falling back to plain XImages"); - HostX.have_shm = FALSE; - xcb_image_destroy(scrpriv->ximg); - } - else { - EPHYR_DBG("SHM segment created %p", scrpriv->shminfo.shmaddr); - scrpriv->ximg->data = scrpriv->shminfo.shmaddr; - shm_success = TRUE; - } - } - - if (!ephyr_glamor && !shm_success) { - EPHYR_DBG("Creating image %dx%d for screen scrpriv=%p\n", - width, buffer_height, scrpriv); - scrpriv->ximg = xcb_image_create_native(HostX.conn, - width, - buffer_height, - XCB_IMAGE_FORMAT_Z_PIXMAP, - HostX.depth, - NULL, - ~0, - NULL); - - /* Match server byte order so that the image can be converted to - * the native byte order by xcb_image_put() before drawing */ - if (host_depth_matches_server(scrpriv)) - scrpriv->ximg->byte_order = IMAGE_BYTE_ORDER; - - scrpriv->ximg->data = - xallocarray(scrpriv->ximg->stride, buffer_height); - } - - if (!HostX.size_set_from_configure) - { - uint32_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; - uint32_t values[2] = {width, height}; - xcb_configure_window(HostX.conn, scrpriv->win, mask, values); - } - - if (scrpriv->win_pre_existing == None && !EphyrWantResize) { - /* Ask the WM to keep our size static */ - xcb_size_hints_t size_hints = {0}; - size_hints.max_width = size_hints.min_width = width; - size_hints.max_height = size_hints.min_height = height; - size_hints.flags = (XCB_ICCCM_SIZE_HINT_P_MIN_SIZE | - XCB_ICCCM_SIZE_HINT_P_MAX_SIZE); - xcb_icccm_set_wm_normal_hints(HostX.conn, scrpriv->win, - &size_hints); - } - -#ifdef GLAMOR - if (!ephyr_glamor_skip_present) -#endif - xcb_map_window(HostX.conn, scrpriv->win); - - /* Set explicit window position if it was informed in - * -screen option (WxH+X or WxH+X+Y). Otherwise, accept the - * position set by WM. - * The trick here is putting this code after xcb_map_window() call, - * so these values won't be overridden by WM. */ - if (scrpriv->win_explicit_position) - { - uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y; - uint32_t values[2] = {x, y}; - xcb_configure_window(HostX.conn, scrpriv->win, mask, values); - } - - - xcb_aux_sync(HostX.conn); - - scrpriv->win_width = width; - scrpriv->win_height = height; - scrpriv->win_x = x; - scrpriv->win_y = y; - -#ifdef GLAMOR - if (ephyr_glamor) { - *bytes_per_line = 0; - ephyr_glamor_set_window_size(scrpriv->glamor, - scrpriv->win_width, scrpriv->win_height); - return NULL; - } else -#endif - if (host_depth_matches_server(scrpriv)) { - *bytes_per_line = scrpriv->ximg->stride; - *bits_per_pixel = scrpriv->ximg->bpp; - - EPHYR_DBG("Host matches server"); - return scrpriv->ximg->data; - } - else { - int bytes_per_pixel = scrpriv->server_depth >> 3; - int stride = (width * bytes_per_pixel + 0x3) & ~0x3; - - *bytes_per_line = stride; - *bits_per_pixel = scrpriv->server_depth; - - EPHYR_DBG("server bpp %i", bytes_per_pixel); - scrpriv->fb_data = xallocarray (stride, buffer_height); - return scrpriv->fb_data; - } -} - -static void hostx_paint_debug_rect(KdScreenInfo *screen, - int x, int y, int width, int height); - -void -hostx_paint_rect(KdScreenInfo *screen, - int sx, int sy, int dx, int dy, int width, int height) -{ - EphyrScrPriv *scrpriv = screen->driver; - - EPHYR_DBG("painting in screen %d\n", scrpriv->mynum); - -#ifdef GLAMOR - if (ephyr_glamor) { - BoxRec box; - RegionRec region; - - box.x1 = dx; - box.y1 = dy; - box.x2 = dx + width; - box.y2 = dy + height; - - RegionInit(®ion, &box, 1); - ephyr_glamor_damage_redisplay(scrpriv->glamor, ®ion); - RegionUninit(®ion); - return; - } -#endif - - /* - * Copy the image data updated by the shadow layer - * on to the window - */ - - if (HostXWantDamageDebug) { - hostx_paint_debug_rect(screen, dx, dy, width, height); - } - - /* - * If the depth of the ephyr server is less than that of the host, - * the kdrive fb does not point to the ximage data but to a buffer - * ( fb_data ), we shift the various bits from this onto the XImage - * so they match the host. - * - * Note, This code is pretty new ( and simple ) so may break on - * endian issues, 32 bpp host etc. - * Not sure if 8bpp case is right either. - * ... and it will be slower than the matching depth case. - */ - - if (!host_depth_matches_server(scrpriv)) { - int x, y, idx, bytes_per_pixel = (scrpriv->server_depth >> 3); - int stride = (scrpriv->win_width * bytes_per_pixel + 0x3) & ~0x3; - unsigned char r, g, b; - unsigned long host_pixel; - - EPHYR_DBG("Unmatched host depth scrpriv=%p\n", scrpriv); - for (y = sy; y < sy + height; y++) - for (x = sx; x < sx + width; x++) { - idx = y * stride + x * bytes_per_pixel; - - switch (scrpriv->server_depth) { - case 16: - { - unsigned short pixel = - *(unsigned short *) (scrpriv->fb_data + idx); - - r = ((pixel & 0xf800) >> 8); - g = ((pixel & 0x07e0) >> 3); - b = ((pixel & 0x001f) << 3); - - host_pixel = (r << 16) | (g << 8) | (b); - - xcb_image_put_pixel(scrpriv->ximg, x, y, host_pixel); - break; - } - case 8: - { - unsigned char pixel = - *(unsigned char *) (scrpriv->fb_data + idx); - xcb_image_put_pixel(scrpriv->ximg, x, y, - scrpriv->cmap[pixel]); - break; - } - default: - break; - } - } - } - - if (HostX.have_shm) { - xcb_image_shm_put(HostX.conn, scrpriv->win, - HostX.gc, scrpriv->ximg, - scrpriv->shminfo, - sx, sy, dx, dy, width, height, FALSE); - } - else { - xcb_image_t *subimg = xcb_image_subimage(scrpriv->ximg, sx, sy, - width, height, 0, 0, 0); - xcb_image_t *img = xcb_image_native(HostX.conn, subimg, 1); - xcb_image_put(HostX.conn, scrpriv->win, HostX.gc, img, dx, dy, 0); - if (subimg != img) - xcb_image_destroy(img); - xcb_image_destroy(subimg); - } - - xcb_aux_sync(HostX.conn); -} - -static void -hostx_paint_debug_rect(KdScreenInfo *screen, - int x, int y, int width, int height) -{ - EphyrScrPriv *scrpriv = screen->driver; - struct timespec tspec; - xcb_rectangle_t rect = { .x = x, .y = y, .width = width, .height = height }; - xcb_void_cookie_t cookie; - xcb_generic_error_t *e; - - tspec.tv_sec = HostX.damage_debug_msec / (1000000); - tspec.tv_nsec = (HostX.damage_debug_msec % 1000000) * 1000; - - EPHYR_DBG("msec: %li tv_sec %li, tv_msec %li", - HostX.damage_debug_msec, tspec.tv_sec, tspec.tv_nsec); - - /* fprintf(stderr, "Xephyr updating: %i+%i %ix%i\n", x, y, width, height); */ - - cookie = xcb_poly_fill_rectangle_checked(HostX.conn, scrpriv->win, - HostX.gc, 1, &rect); - e = xcb_request_check(HostX.conn, cookie); - free(e); - - /* nanosleep seems to work better than usleep for me... */ - nanosleep(&tspec, NULL); -} - -Bool -hostx_load_keymap(KeySymsPtr keySyms, CARD8 *modmap, XkbControlsPtr controls) -{ - int min_keycode, max_keycode; - int map_width; - size_t i, j; - int keymap_len; - xcb_keysym_t *keymap; - xcb_keycode_t *modifier_map; - xcb_get_keyboard_mapping_cookie_t mapping_c; - xcb_get_keyboard_mapping_reply_t *mapping_r; - xcb_get_modifier_mapping_cookie_t modifier_c; - xcb_get_modifier_mapping_reply_t *modifier_r; - xcb_xkb_use_extension_cookie_t use_c; - xcb_xkb_use_extension_reply_t *use_r; - xcb_xkb_get_controls_cookie_t controls_c; - xcb_xkb_get_controls_reply_t *controls_r; - - /* First of all, collect host X server's - * min_keycode and max_keycode, which are - * independent from XKB support. */ - min_keycode = xcb_get_setup(HostX.conn)->min_keycode; - max_keycode = xcb_get_setup(HostX.conn)->max_keycode; - - EPHYR_DBG("min: %d, max: %d", min_keycode, max_keycode); - - keySyms->minKeyCode = min_keycode; - keySyms->maxKeyCode = max_keycode; - - /* Check for XKB availability in host X server */ - if (!hostx_has_extension(&xcb_xkb_id)) { - EPHYR_LOG_ERROR("XKB extension is not supported in host X server."); - return FALSE; - } - - use_c = xcb_xkb_use_extension(HostX.conn, - XCB_XKB_MAJOR_VERSION, - XCB_XKB_MINOR_VERSION); - use_r = xcb_xkb_use_extension_reply(HostX.conn, use_c, NULL); - - if (!use_r) { - EPHYR_LOG_ERROR("Couldn't use XKB extension."); - return FALSE; - } else if (!use_r->supported) { - EPHYR_LOG_ERROR("XKB extension is not supported in host X server."); - free(use_r); - return FALSE; - } - - free(use_r); - - /* Send all needed XCB requests at once, - * and process the replies as needed. */ - mapping_c = xcb_get_keyboard_mapping(HostX.conn, - min_keycode, - max_keycode - min_keycode + 1); - modifier_c = xcb_get_modifier_mapping(HostX.conn); - controls_c = xcb_xkb_get_controls(HostX.conn, - XCB_XKB_ID_USE_CORE_KBD); - - mapping_r = xcb_get_keyboard_mapping_reply(HostX.conn, - mapping_c, - NULL); - - if (!mapping_r) { - EPHYR_LOG_ERROR("xcb_get_keyboard_mapping_reply() failed."); - return FALSE; - } - - map_width = mapping_r->keysyms_per_keycode; - keymap = xcb_get_keyboard_mapping_keysyms(mapping_r); - keymap_len = xcb_get_keyboard_mapping_keysyms_length(mapping_r); - - keySyms->mapWidth = map_width; - keySyms->map = calloc(keymap_len, sizeof(KeySym)); - - if (!keySyms->map) { - EPHYR_LOG_ERROR("Failed to allocate KeySym map."); - free(mapping_r); - return FALSE; - } - - for (i = 0; i < keymap_len; i++) { - keySyms->map[i] = keymap[i]; - } - - free(mapping_r); - - modifier_r = xcb_get_modifier_mapping_reply(HostX.conn, - modifier_c, - NULL); - - if (!modifier_r) { - EPHYR_LOG_ERROR("xcb_get_modifier_mapping_reply() failed."); - return FALSE; - } - - modifier_map = xcb_get_modifier_mapping_keycodes(modifier_r); - memset(modmap, 0, sizeof(CARD8) * MAP_LENGTH); - - for (j = 0; j < 8; j++) { - for (i = 0; i < modifier_r->keycodes_per_modifier; i++) { - CARD8 keycode; - - if ((keycode = modifier_map[j * modifier_r->keycodes_per_modifier + i])) { - modmap[keycode] |= 1 << j; - } - } - } - - free(modifier_r); - - controls_r = xcb_xkb_get_controls_reply(HostX.conn, - controls_c, - NULL); - - if (!controls_r) { - EPHYR_LOG_ERROR("xcb_xkb_get_controls_reply() failed."); - return FALSE; - } - - controls->enabled_ctrls = controls_r->enabledControls; - - for (i = 0; i < XkbPerKeyBitArraySize; i++) { - controls->per_key_repeat[i] = controls_r->perKeyRepeat[i]; - } - - free(controls_r); - - return TRUE; -} - -void -hostx_size_set_from_configure(Bool ss) -{ - HostX.size_set_from_configure = ss; -} - -xcb_connection_t * -hostx_get_xcbconn(void) -{ - return HostX.conn; -} - -xcb_generic_event_t * -hostx_get_event(Bool queued_only) -{ - xcb_generic_event_t *xev; - - if (HostX.saved_event) { - xev = HostX.saved_event; - HostX.saved_event = NULL; - } else { - if (queued_only) - xev = xcb_poll_for_queued_event(HostX.conn); - else - xev = xcb_poll_for_event(HostX.conn); - } - return xev; -} - -Bool -hostx_has_queued_event(void) -{ - if (!HostX.saved_event) - HostX.saved_event = xcb_poll_for_queued_event(HostX.conn); - return HostX.saved_event != NULL; -} - -int -hostx_get_screen(void) -{ - return HostX.screen; -} - -int -hostx_get_fd(void) -{ - return xcb_get_file_descriptor(HostX.conn); -} - -int -hostx_get_window(int a_screen_number) -{ - EphyrScrPriv *scrpriv; - if (a_screen_number < 0 || a_screen_number >= HostX.n_screens) { - EPHYR_LOG_ERROR("bad screen number:%d\n", a_screen_number); - return 0; - } - scrpriv = HostX.screens[a_screen_number]->driver; - return scrpriv->win; -} - -int -hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs) -{ - xcb_get_geometry_cookie_t geom_cookie; - xcb_get_window_attributes_cookie_t attr_cookie; - xcb_get_geometry_reply_t *geom_reply; - xcb_get_window_attributes_reply_t *attr_reply; - - geom_cookie = xcb_get_geometry(HostX.conn, a_window); - attr_cookie = xcb_get_window_attributes(HostX.conn, a_window); - geom_reply = xcb_get_geometry_reply(HostX.conn, geom_cookie, NULL); - attr_reply = xcb_get_window_attributes_reply(HostX.conn, attr_cookie, NULL); - - a_attrs->x = geom_reply->x; - a_attrs->y = geom_reply->y; - a_attrs->width = geom_reply->width; - a_attrs->height = geom_reply->height; - a_attrs->visualid = attr_reply->visual; - - free(geom_reply); - free(attr_reply); - return TRUE; -} - -int -hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries) -{ - Bool is_ok = FALSE; - EphyrHostVisualInfo *host_visuals = NULL; - int nb_items = 0, i = 0, screen_num; - xcb_screen_iterator_t screens; - xcb_depth_iterator_t depths; - - EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, FALSE); - EPHYR_LOG("enter\n"); - - screens = xcb_setup_roots_iterator(xcb_get_setup(HostX.conn)); - for (screen_num = 0; screens.rem; screen_num++, xcb_screen_next(&screens)) { - depths = xcb_screen_allowed_depths_iterator(screens.data); - for (; depths.rem; xcb_depth_next(&depths)) { - xcb_visualtype_t *visuals = xcb_depth_visuals(depths.data); - EphyrHostVisualInfo *tmp_visuals = - reallocarray(host_visuals, - nb_items + depths.data->visuals_len, - sizeof(EphyrHostVisualInfo)); - if (!tmp_visuals) { - goto out; - } - host_visuals = tmp_visuals; - for (i = 0; i < depths.data->visuals_len; i++) { - host_visuals[nb_items + i].visualid = visuals[i].visual_id; - host_visuals[nb_items + i].screen = screen_num; - host_visuals[nb_items + i].depth = depths.data->depth; - host_visuals[nb_items + i].class = visuals[i]._class; - host_visuals[nb_items + i].red_mask = visuals[i].red_mask; - host_visuals[nb_items + i].green_mask = visuals[i].green_mask; - host_visuals[nb_items + i].blue_mask = visuals[i].blue_mask; - host_visuals[nb_items + i].colormap_size = visuals[i].colormap_entries; - host_visuals[nb_items + i].bits_per_rgb = visuals[i].bits_per_rgb_value; - } - nb_items += depths.data->visuals_len; - } - } - - EPHYR_LOG("host advertises %d visuals\n", nb_items); - *a_visuals = host_visuals; - *a_num_entries = nb_items; - host_visuals = NULL; - - is_ok = TRUE; -out: - free(host_visuals); - host_visuals = NULL; - EPHYR_LOG("leave\n"); - return is_ok; - -} - -int -hostx_create_window(int a_screen_number, - EphyrBox * a_geometry, - int a_visual_id, int *a_host_peer /*out parameter */ ) -{ - Bool is_ok = FALSE; - xcb_window_t win; - int winmask = 0; - uint32_t attrs[2]; - xcb_screen_t *screen = xcb_aux_get_screen(HostX.conn, hostx_get_screen()); - xcb_visualtype_t *visual; - int depth = 0; - EphyrScrPriv *scrpriv = HostX.screens[a_screen_number]->driver; - - EPHYR_RETURN_VAL_IF_FAIL(screen && a_geometry, FALSE); - - EPHYR_LOG("enter\n"); - - visual = xcb_aux_find_visual_by_id(screen, a_visual_id); - if (!visual) { - EPHYR_LOG_ERROR ("argh, could not find a remote visual with id:%d\n", - a_visual_id); - goto out; - } - depth = xcb_aux_get_depth_of_visual(screen, a_visual_id); - - winmask = XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; - attrs[0] = XCB_EVENT_MASK_BUTTON_PRESS - |XCB_EVENT_MASK_BUTTON_RELEASE - |XCB_EVENT_MASK_POINTER_MOTION - |XCB_EVENT_MASK_KEY_PRESS - |XCB_EVENT_MASK_KEY_RELEASE - |XCB_EVENT_MASK_EXPOSURE; - attrs[1] = xcb_generate_id(HostX.conn); - xcb_create_colormap(HostX.conn, - XCB_COLORMAP_ALLOC_NONE, - attrs[1], - hostx_get_window(a_screen_number), - a_visual_id); - - win = xcb_generate_id(HostX.conn); - xcb_create_window(HostX.conn, - depth, - win, - hostx_get_window (a_screen_number), - a_geometry->x, a_geometry->y, - a_geometry->width, a_geometry->height, 0, - XCB_WINDOW_CLASS_COPY_FROM_PARENT, - a_visual_id, winmask, attrs); - - if (scrpriv->peer_win == XCB_NONE) { - scrpriv->peer_win = win; - } - else { - EPHYR_LOG_ERROR("multiple peer windows created for same screen\n"); - } - xcb_flush(HostX.conn); - xcb_map_window(HostX.conn, win); - *a_host_peer = win; - is_ok = TRUE; - out: - EPHYR_LOG("leave\n"); - return is_ok; -} - -int -hostx_destroy_window(int a_win) -{ - xcb_destroy_window(HostX.conn, a_win); - xcb_flush(HostX.conn); - return TRUE; -} - -int -hostx_set_window_geometry(int a_win, EphyrBox * a_geo) -{ - uint32_t mask = XCB_CONFIG_WINDOW_X - | XCB_CONFIG_WINDOW_Y - | XCB_CONFIG_WINDOW_WIDTH - | XCB_CONFIG_WINDOW_HEIGHT; - uint32_t values[4]; - - EPHYR_RETURN_VAL_IF_FAIL(a_geo, FALSE); - - EPHYR_LOG("enter. x,y,w,h:(%d,%d,%d,%d)\n", - a_geo->x, a_geo->y, a_geo->width, a_geo->height); - - values[0] = a_geo->x; - values[1] = a_geo->y; - values[2] = a_geo->width; - values[3] = a_geo->height; - xcb_configure_window(HostX.conn, a_win, mask, values); - - EPHYR_LOG("leave\n"); - return TRUE; -} - -int -hostx_set_window_bounding_rectangles(int a_window, - EphyrRect * a_rects, int a_num_rects) -{ - Bool is_ok = FALSE; - int i = 0; - xcb_rectangle_t *rects = NULL; - - EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE); - - EPHYR_LOG("enter. num rects:%d\n", a_num_rects); - - rects = calloc(a_num_rects, sizeof (xcb_rectangle_t)); - if (!rects) - goto out; - for (i = 0; i < a_num_rects; i++) { - rects[i].x = a_rects[i].x1; - rects[i].y = a_rects[i].y1; - rects[i].width = abs(a_rects[i].x2 - a_rects[i].x1); - rects[i].height = abs(a_rects[i].y2 - a_rects[i].y1); - EPHYR_LOG("borders clipped to rect[x:%d,y:%d,w:%d,h:%d]\n", - rects[i].x, rects[i].y, rects[i].width, rects[i].height); - } - xcb_shape_rectangles(HostX.conn, - XCB_SHAPE_SO_SET, - XCB_SHAPE_SK_BOUNDING, - XCB_CLIP_ORDERING_YX_BANDED, - a_window, - 0, 0, - a_num_rects, - rects); - is_ok = TRUE; - -out: - free(rects); - rects = NULL; - EPHYR_LOG("leave\n"); - return is_ok; -} - -#ifdef GLAMOR -Bool -ephyr_glamor_init(ScreenPtr screen) -{ - KdScreenPriv(screen); - KdScreenInfo *kd_screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = kd_screen->driver; - - scrpriv->glamor = ephyr_glamor_glx_screen_init(scrpriv->win); - ephyr_glamor_set_window_size(scrpriv->glamor, - scrpriv->win_width, scrpriv->win_height); - - if (!glamor_init(screen, 0)) { - FatalError("Failed to initialize glamor\n"); - return FALSE; - } - - return TRUE; -} - -static int -ephyrSetPixmapVisitWindow(WindowPtr window, void *data) -{ - ScreenPtr screen = window->drawable.pScreen; - - if (screen->GetWindowPixmap(window) == data) { - screen->SetWindowPixmap(window, screen->GetScreenPixmap(screen)); - return WT_WALKCHILDREN; - } - return WT_DONTWALKCHILDREN; -} - -Bool -ephyr_glamor_create_screen_resources(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *kd_screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = kd_screen->driver; - PixmapPtr old_screen_pixmap, screen_pixmap; - uint32_t tex; - - if (!ephyr_glamor) - return TRUE; - - /* kdrive's fbSetupScreen() told mi to have - * miCreateScreenResources() (which is called before this) make a - * scratch pixmap wrapping ephyr-glamor's NULL - * KdScreenInfo->fb.framebuffer. - * - * We want a real (texture-based) screen pixmap at this point. - * This is what glamor will render into, and we'll then texture - * out of that into the host's window to present the results. - * - * Thus, delete the current screen pixmap, and put a fresh one in. - */ - old_screen_pixmap = pScreen->GetScreenPixmap(pScreen); - pScreen->DestroyPixmap(old_screen_pixmap); - - screen_pixmap = pScreen->CreatePixmap(pScreen, - pScreen->width, - pScreen->height, - pScreen->rootDepth, - GLAMOR_CREATE_NO_LARGE); - if (!screen_pixmap) - return FALSE; - - pScreen->SetScreenPixmap(screen_pixmap); - if (pScreen->root && pScreen->SetWindowPixmap) - TraverseTree(pScreen->root, ephyrSetPixmapVisitWindow, old_screen_pixmap); - - /* Tell the GLX code what to GL texture to read from. */ - tex = glamor_get_pixmap_texture(screen_pixmap); - if (!tex) - return FALSE; - - ephyr_glamor_set_texture(scrpriv->glamor, tex); - - return TRUE; -} - -void -ephyr_glamor_enable(ScreenPtr screen) -{ -} - -void -ephyr_glamor_disable(ScreenPtr screen) -{ -} - -void -ephyr_glamor_fini(ScreenPtr screen) -{ - KdScreenPriv(screen); - KdScreenInfo *kd_screen = pScreenPriv->screen; - EphyrScrPriv *scrpriv = kd_screen->driver; - - glamor_fini(screen); - ephyr_glamor_glx_screen_fini(scrpriv->glamor); - scrpriv->glamor = NULL; -} -#endif diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h deleted file mode 100644 index 4b2678e58..000000000 --- a/hw/kdrive/ephyr/hostx.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Xephyr - A kdrive X server that runs in a host X window. - * Authored by Matthew Allum - * - * Copyright © 2004 Nokia - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Nokia not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Nokia makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * NOKIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _XLIBS_STUFF_H_ -#define _XLIBS_STUFF_H_ - -#include -#include -#include -#include -#include "ephyr.h" - -#define EPHYR_WANT_DEBUG 0 - -#if (EPHYR_WANT_DEBUG) -#define EPHYR_DBG(x, a...) \ - fprintf(stderr, __FILE__ ":%d,%s() " x "\n", __LINE__, __func__, ##a) -#else -#define EPHYR_DBG(x, a...) do {} while (0) -#endif - -typedef struct EphyrHostXVars EphyrHostXVars; - -typedef struct { - VisualID visualid; - int screen; - int depth; - int class; - unsigned long red_mask; - unsigned long green_mask; - unsigned long blue_mask; - int colormap_size; - int bits_per_rgb; -} EphyrHostVisualInfo; - -typedef struct { - int x, y; - int width, height; - int visualid; -} EphyrHostWindowAttributes; - -typedef struct { - int x, y, width, height; -} EphyrBox; - -typedef struct { - short x1, y1, x2, y2; -} EphyrRect; - -int -hostx_want_screen_geometry(KdScreenInfo *screen, int *width, int *height, int *x, int *y); - -int - hostx_want_host_cursor(void); - -void - hostx_use_sw_cursor(void); - -xcb_cursor_t - hostx_get_empty_cursor(void); - -void - hostx_get_output_geometry(const char *output, - int *x, int *y, - int *width, int *height); - -void - hostx_use_fullscreen(void); - -int - hostx_want_fullscreen(void); - -int -hostx_want_preexisting_window(KdScreenInfo *screen); - -void - hostx_use_preexisting_window(unsigned long win_id); - -void - hostx_use_resname(char *name, int fromcmd); - -void - hostx_set_title(char *name); - -void - hostx_handle_signal(int signum); - -int - hostx_init(void); - -void -hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry, const char *output); - -void - hostx_set_display_name(char *name); - -void -hostx_set_screen_number(KdScreenInfo *screen, int number); - -void -hostx_set_win_title(KdScreenInfo *screen, const char *extra_text); - -int - hostx_get_depth(void); - -int -hostx_get_server_depth(KdScreenInfo *screen); - -int -hostx_get_bpp(KdScreenInfo *screen); - -void -hostx_get_visual_masks(KdScreenInfo *screen, - CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk); -void - -hostx_set_cmap_entry(ScreenPtr pScreen, unsigned char idx, - unsigned char r, unsigned char g, unsigned char b); - -void *hostx_screen_init(KdScreenInfo *screen, - int x, int y, - int width, int height, int buffer_height, - int *bytes_per_line, int *bits_per_pixel); - -void -hostx_paint_rect(KdScreenInfo *screen, - int sx, int sy, int dx, int dy, int width, int height); - -Bool -hostx_load_keymap(KeySymsPtr keySyms, CARD8 *modmap, XkbControlsPtr controls); - -void -hostx_size_set_from_configure(Bool); - -xcb_connection_t * -hostx_get_xcbconn(void); - -xcb_generic_event_t * -hostx_get_event(Bool queued_only); - -Bool -hostx_has_queued_event(void); - -int -hostx_get_screen(void); - -int - hostx_get_window(int a_screen_number); - -int - hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attr); - -int - hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries); - -int hostx_create_window(int a_screen_number, - EphyrBox * a_geometry, - int a_visual_id, int *a_host_win /*out parameter */ ); - -int hostx_destroy_window(int a_win); - -int hostx_set_window_geometry(int a_win, EphyrBox * a_geo); - -int hostx_set_window_bounding_rectangles(int a_window, - EphyrRect * a_rects, int a_num_rects); - -int hostx_has_extension(xcb_extension_t *extension); - -int hostx_get_fd(void); - -#endif /*_XLIBS_STUFF_H_*/ diff --git a/hw/kdrive/ephyr/man/Xephyr.man b/hw/kdrive/ephyr/man/Xephyr.man deleted file mode 100644 index cc8a80f21..000000000 --- a/hw/kdrive/ephyr/man/Xephyr.man +++ /dev/null @@ -1,96 +0,0 @@ -.\" -.\" Copyright (c) Matthieu Herrb -.\" -.\" Permission to use, copy, modify, and distribute this software for any -.\" purpose with or without fee is hereby granted, provided that the above -.\" copyright notice and this permission notice appear in all copies. -.\" -.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -.\" ANY SPECIAL, DIRECT, 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. -.\" -.TH Xephyr @appmansuffix@ @vendorversion@ -.SH NAME -Xephyr - X server outputting to a window on a pre-existing X display -.SH SYNOPSIS -.B Xephyr -.RI [\fB:\fP display ] -.RI [ option -.IR ... ] -.SH DESCRIPTION -.B Xephyr -is a kdrive server that outputs to a window on a pre-existing "host" -X display. -Think -.I Xnest -but with support for modern extensions like composite, damage and randr. -.PP -Unlike -.I Xnest -which is an X proxy, i.e. limited to the capabilities of the host X server, -.B Xephyr -is a real X server which -uses the host X server window as "framebuffer" via fast SHM XImages. -.PP -It also has support for "visually" debugging what the server is -painting. -.SH OPTIONS -The server accepts all the standard options of Xserver(@appmansuffix@) -and the following additional options: -.TP 8 -.BI -screen " width" x height -sets the screen size. -.TP 8 -.BI -parent " id" -uses existing window -.I id . -If a -.BI -screen -argument follows a -.BI -parent -argument, this screen is embedded into the given window. -.TP 8 -.B -host-cursor -set 'cursor acceleration': -The host's cursor is reused. This is only really there to aid -debugging by avoiding server paints for the cursor. Performance -improvement is negligible. -.TP 8 -.B -resizeable -Allow the Xephyr window to be resized, even if not embedded into a parent -window. By default, the Xephyr window has a fixed size. -.TP 8 -.B -no-host-grab -Disable grabbing the keyboard and mouse. -.SH "SIGNALS" -Send a SIGUSR1 to the server (e.g. pkill -USR1 Xephyr) to -toggle the debugging mode. -In this mode red rectangles are painted to -screen areas getting painted before painting the actual content. -The -delay between this can be altered by setting a XEPHYR_PAUSE env var to -a value in micro seconds. -.SH CAVEATS -.PP -.IP \(bu 2 -Rotated displays are currently updated via full blits. This -is slower than a normal orientated display. Debug mode will -therefore not be of much use rotated. -.IP \(bu 2 -The '-host-cursor' cursor is static in its appearance. -.IP \(bu 2 -The build gets a warning about 'nanosleep'. I think the various '-D' -build flags are causing this. I haven't figured as yet how to work -round it. It doesn't appear to break anything however. -.IP \(bu 2 -Keyboard handling is basic but works. -.IP \(bu 2 -Mouse button 5 probably won't work. -.SH "SEE ALSO" -X(@miscmansuffix@), Xserver(@appmansuffix@) -.SH AUTHOR -Matthew Allum 2004 diff --git a/hw/kdrive/ephyr/meson.build b/hw/kdrive/ephyr/meson.build deleted file mode 100644 index 9e329ba67..000000000 --- a/hw/kdrive/ephyr/meson.build +++ /dev/null @@ -1,70 +0,0 @@ -srcs = [ - 'ephyr.c', - 'ephyrinit.c', - 'ephyrcursor.c', - 'ephyr_draw.c', - 'hostx.c', -] - -xephyr_dep = [ - common_dep, - dependency('xcb'), - dependency('xcb-shape'), - dependency('xcb-render'), - dependency('xcb-renderutil'), - dependency('xcb-aux'), - dependency('xcb-image'), - dependency('xcb-icccm'), - dependency('xcb-shm', version : '>=1.9.3'), - dependency('xcb-keysyms'), - dependency('xcb-randr'), - dependency('xcb-xkb'), -] - -xephyr_glamor = [] -if build_glamor - srcs += 'ephyr_glamor_glx.c' - if build_xv - srcs += 'ephyr_glamor_xv.c' - endif - xephyr_glamor += glamor - xephyr_glamor += glamor_egl_stubs - xephyr_dep += dependency('x11-xcb') - xephyr_dep += epoxy_dep -endif - -if build_xv - srcs += 'ephyrvideo.c' - xephyr_dep += dependency('xcb-xv') -endif - -xephyr_server = executable( - 'Xephyr', - srcs, - include_directories: [ - inc, - include_directories('../src') - ], - dependencies: xephyr_dep, - link_with: [ - libxserver_main, - libxserver_exa, - xephyr_glamor, - kdrive, - libxserver_fb, - libxserver, - libxserver_config, - libxserver_xkb_stubs, - libxserver_xi_stubs, - libxserver_glx, - libglxvnd, - ], - install: true, -) - -xephyr_man = configure_file( - input: 'man/Xephyr.man', - output: 'Xephyr.1', - configuration: manpage_config, -) -install_man(xephyr_man) diff --git a/hw/kdrive/meson.build b/hw/kdrive/meson.build deleted file mode 100644 index 16341e228..000000000 --- a/hw/kdrive/meson.build +++ /dev/null @@ -1,2 +0,0 @@ -subdir('src') -subdir('ephyr') diff --git a/hw/kdrive/src/kcmap.c b/hw/kdrive/src/kcmap.c deleted file mode 100644 index b8697ca63..000000000 --- a/hw/kdrive/src/kcmap.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright © 1999 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "kdrive.h" - -/* - * Put the entire colormap into the DAC - */ - -static void -KdSetColormap(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - ColormapPtr pCmap = pScreenPriv->pInstalledmap; - Pixel pixels[KD_MAX_PSEUDO_SIZE]; - xrgb colors[KD_MAX_PSEUDO_SIZE]; - xColorItem defs[KD_MAX_PSEUDO_SIZE]; - int i; - - if (!pScreenPriv->card->cfuncs->putColors) - return; - if (pScreenPriv->screen->fb.depth > KD_MAX_PSEUDO_DEPTH) - return; - - if (!pScreenPriv->enabled) - return; - - if (!pCmap) - return; - - /* - * Make DIX convert pixels into RGB values -- this handles - * true/direct as well as pseudo/static visuals - */ - - for (i = 0; i < (1 << pScreenPriv->screen->fb.depth); i++) - pixels[i] = i; - - QueryColors(pCmap, (1 << pScreenPriv->screen->fb.depth), pixels, colors, - serverClient); - - for (i = 0; i < (1 << pScreenPriv->screen->fb.depth); i++) { - defs[i].pixel = i; - defs[i].red = colors[i].red; - defs[i].green = colors[i].green; - defs[i].blue = colors[i].blue; - defs[i].flags = DoRed | DoGreen | DoBlue; - } - - (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, - (1 << pScreenPriv->screen->fb. - depth), defs); -} - -/* - * When the hardware is enabled, save the hardware colors and store - * the current colormap - */ -void -KdEnableColormap(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - int i; - - if (!pScreenPriv->card->cfuncs->putColors) - return; - - if (pScreenPriv->screen->fb.depth <= KD_MAX_PSEUDO_DEPTH) { - for (i = 0; i < (1 << pScreenPriv->screen->fb.depth); i++) - pScreenPriv->systemPalette[i].pixel = i; - (*pScreenPriv->card->cfuncs->getColors) (pScreen, - (1 << pScreenPriv->screen->fb. - depth), - pScreenPriv->systemPalette); - } - KdSetColormap(pScreen); -} - -void -KdDisableColormap(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - - if (!pScreenPriv->card->cfuncs->putColors) - return; - - if (pScreenPriv->screen->fb.depth <= KD_MAX_PSEUDO_DEPTH) { - (*pScreenPriv->card->cfuncs->putColors) (pScreen, - (1 << pScreenPriv->screen->fb. - depth), - pScreenPriv->systemPalette); - } -} - -/* - * KdInstallColormap - * - * This function is called when the server receives a request to install a - * colormap or when the server needs to install one on its own, like when - * there's no window manager running and the user has moved the pointer over - * an X client window. It needs to build an identity Windows palette for the - * colormap and realize it into the Windows system palette. - */ -void -KdInstallColormap(ColormapPtr pCmap) -{ - KdScreenPriv(pCmap->pScreen); - - if (pCmap == pScreenPriv->pInstalledmap) - return; - - /* Tell X clients that the installed colormap is going away. */ - if (pScreenPriv->pInstalledmap) - WalkTree(pScreenPriv->pInstalledmap->pScreen, TellLostMap, - (void *) &(pScreenPriv->pInstalledmap->mid)); - - /* Take note of the new installed colorscreen-> */ - pScreenPriv->pInstalledmap = pCmap; - - KdSetColormap(pCmap->pScreen); - - /* Tell X clients of the new colormap */ - WalkTree(pCmap->pScreen, TellGainedMap, (void *) &(pCmap->mid)); -} - -/* - * KdUninstallColormap - * - * This function uninstalls a colormap by either installing - * the default X colormap or erasing the installed colormap pointer. - * The default X colormap itself cannot be uninstalled. - */ -void -KdUninstallColormap(ColormapPtr pCmap) -{ - KdScreenPriv(pCmap->pScreen); - Colormap defMapID; - ColormapPtr defMap; - - /* ignore if not installed */ - if (pCmap != pScreenPriv->pInstalledmap) - return; - - /* ignore attempts to uninstall default colormap */ - defMapID = pCmap->pScreen->defColormap; - if ((Colormap) pCmap->mid == defMapID) - return; - - /* install default */ - dixLookupResourceByType((void **) &defMap, defMapID, RT_COLORMAP, - serverClient, DixInstallAccess); - if (defMap) - (*pCmap->pScreen->InstallColormap) (defMap); - else { - /* uninstall and clear colormap pointer */ - WalkTree(pCmap->pScreen, TellLostMap, (void *) &(pCmap->mid)); - pScreenPriv->pInstalledmap = 0; - } -} - -int -KdListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmaps) -{ - KdScreenPriv(pScreen); - int n = 0; - - if (pScreenPriv->pInstalledmap) { - *pCmaps++ = pScreenPriv->pInstalledmap->mid; - n++; - } - return n; -} - -/* - * KdStoreColors - * - * This function is called whenever the server receives a request to store - * color values into one or more entries in the currently installed X - * colormap; it can be either the default colormap or a private colorscreen-> - */ -void -KdStoreColors(ColormapPtr pCmap, int ndef, xColorItem * pdefs) -{ - KdScreenPriv(pCmap->pScreen); - VisualPtr pVisual; - xColorItem expanddefs[KD_MAX_PSEUDO_SIZE]; - - if (pCmap != pScreenPriv->pInstalledmap) - return; - - if (!pScreenPriv->card->cfuncs->putColors) - return; - - if (pScreenPriv->screen->fb.depth > KD_MAX_PSEUDO_DEPTH) - return; - - if (!pScreenPriv->enabled) - return; - - /* Check for DirectColor or TrueColor being simulated on a PseudoColor device. */ - pVisual = pCmap->pVisual; - if ((pVisual->class | DynamicClass) == DirectColor) { - /* - * Expand DirectColor or TrueColor color values into a PseudoColor - * format. Defer to the Color Framebuffer (CFB) code to do that. - */ - ndef = fbExpandDirectColors(pCmap, ndef, pdefs, expanddefs); - pdefs = expanddefs; - } - - (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, ndef, pdefs); -} diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c deleted file mode 100644 index 8de01ccfa..000000000 --- a/hw/kdrive/src/kdrive.c +++ /dev/null @@ -1,1017 +0,0 @@ -/* - * Copyright © 1999 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "kdrive.h" -#include -#include -#include "privates.h" -#ifdef RANDR -#include -#endif -#include "glx_extinit.h" - -#ifdef XV -#include "kxv.h" -#endif - -#ifdef DPMSExtension -#include "dpmsproc.h" -#endif - -#ifdef HAVE_EXECINFO_H -#include -#endif - -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) -#include -#endif - -/* This stub can be safely removed once we can - * split input and GPU parts in hotplug.h et al. */ -#include - -typedef struct _kdDepths { - CARD8 depth; - CARD8 bpp; -} KdDepths; - -KdDepths kdDepths[] = { - {1, 1}, - {4, 4}, - {8, 8}, - {15, 16}, - {16, 16}, - {24, 32}, - {32, 32} -}; - -#define KD_DEFAULT_BUTTONS 5 - -DevPrivateKeyRec kdScreenPrivateKeyRec; -static unsigned long kdGeneration; - -Bool kdEmulateMiddleButton; -Bool kdRawPointerCoordinates; -Bool kdDisableZaphod; -static Bool kdEnabled; -static int kdSubpixelOrder; -static char *kdSwitchCmd; -static DDXPointRec kdOrigin; -Bool kdHasPointer = FALSE; -Bool kdHasKbd = FALSE; -const char *kdGlobalXkbRules = NULL; -const char *kdGlobalXkbModel = NULL; -const char *kdGlobalXkbLayout = NULL; -const char *kdGlobalXkbVariant = NULL; -const char *kdGlobalXkbOptions = NULL; - -void -KdDisableScreen(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - - if (!pScreenPriv->enabled) - return; - if (!pScreenPriv->closed) - SetRootClip(pScreen, ROOT_CLIP_NONE); - KdDisableColormap(pScreen); - if (!pScreenPriv->screen->dumb && pScreenPriv->card->cfuncs->disableAccel) - (*pScreenPriv->card->cfuncs->disableAccel) (pScreen); - pScreenPriv->enabled = FALSE; -} - -static void -KdDoSwitchCmd(const char *reason) -{ - if (kdSwitchCmd) { - char *command; - int ret; - - if (asprintf(&command, "%s %s", kdSwitchCmd, reason) == -1) - return; - - /* Ignore the return value from system; I'm not sure - * there's anything more useful to be done when - * it fails - */ - ret = system(command); - (void) ret; - free(command); - } -} - -static void -KdSuspend(void) -{ - KdCardInfo *card; - KdScreenInfo *screen; - - if (kdEnabled) { - for (card = kdCardInfo; card; card = card->next) { - for (screen = card->screenList; screen; screen = screen->next) - if (screen->mynum == card->selected && screen->pScreen) - KdDisableScreen(screen->pScreen); - } - KdDisableInput(); - KdDoSwitchCmd("suspend"); - } -} - -static void -KdDisableScreens(void) -{ - KdSuspend(); - kdEnabled = FALSE; -} - -Bool -KdEnableScreen(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - - if (pScreenPriv->enabled) - return TRUE; - pScreenPriv->enabled = TRUE; - pScreenPriv->dpmsState = KD_DPMS_NORMAL; - pScreenPriv->card->selected = pScreenPriv->screen->mynum; - if (!pScreenPriv->screen->dumb && pScreenPriv->card->cfuncs->enableAccel) - (*pScreenPriv->card->cfuncs->enableAccel) (pScreen); - KdEnableColormap(pScreen); - SetRootClip(pScreen, ROOT_CLIP_FULL); - return TRUE; -} - -void -ddxGiveUp(enum ExitCode error) -{ - KdDisableScreens(); -} - -static Bool kdDumbDriver; -static Bool kdSoftCursor; - -const char * -KdParseFindNext(const char *cur, const char *delim, char *save, char *last) -{ - while (*cur && !strchr(delim, *cur)) { - *save++ = *cur++; - } - *save = 0; - *last = *cur; - if (*cur) - cur++; - return cur; -} - -Rotation -KdAddRotation(Rotation a, Rotation b) -{ - Rotation rotate = (a & RR_Rotate_All) * (b & RR_Rotate_All); - Rotation reflect = (a & RR_Reflect_All) ^ (b & RR_Reflect_All); - - if (rotate > RR_Rotate_270) - rotate /= (RR_Rotate_270 * RR_Rotate_90); - return reflect | rotate; -} - -Rotation -KdSubRotation(Rotation a, Rotation b) -{ - Rotation rotate = (a & RR_Rotate_All) * 16 / (b & RR_Rotate_All); - Rotation reflect = (a & RR_Reflect_All) ^ (b & RR_Reflect_All); - - if (rotate > RR_Rotate_270) - rotate /= (RR_Rotate_270 * RR_Rotate_90); - return reflect | rotate; -} - -void -KdParseScreen(KdScreenInfo * screen, const char *arg) -{ - char delim; - char save[1024]; - int i; - int pixels, mm; - - screen->dumb = kdDumbDriver; - screen->softCursor = kdSoftCursor; - screen->origin = kdOrigin; - screen->randr = RR_Rotate_0; - screen->x = 0; - screen->y = 0; - screen->width = 0; - screen->height = 0; - screen->width_mm = 0; - screen->height_mm = 0; - screen->subpixel_order = kdSubpixelOrder; - screen->rate = 0; - screen->fb.depth = 0; - if (!arg) - return; - if (strlen(arg) >= sizeof(save)) - return; - - for (i = 0; i < 2; i++) { - arg = KdParseFindNext(arg, "x/+@XY", save, &delim); - if (!save[0]) - return; - - pixels = atoi(save); - mm = 0; - - if (delim == '/') { - arg = KdParseFindNext(arg, "x+@XY", save, &delim); - if (!save[0]) - return; - mm = atoi(save); - } - - if (i == 0) { - screen->width = pixels; - screen->width_mm = mm; - } - else { - screen->height = pixels; - screen->height_mm = mm; - } - if (delim != 'x' && delim != '+' && delim != '@' && - delim != 'X' && delim != 'Y' && - (delim != '\0' || i == 0)) - return; - } - - kdOrigin.x += screen->width; - kdOrigin.y = 0; - kdDumbDriver = FALSE; - kdSoftCursor = FALSE; - kdSubpixelOrder = SubPixelUnknown; - - if (delim == '+') { - arg = KdParseFindNext(arg, "+@xXY", save, &delim); - if (save[0]) - screen->x = atoi(save); - } - - if (delim == '+') { - arg = KdParseFindNext(arg, "@xXY", save, &delim); - if (save[0]) - screen->y = atoi(save); - } - - if (delim == '@') { - arg = KdParseFindNext(arg, "xXY", save, &delim); - if (save[0]) { - int rotate = atoi(save); - - if (rotate < 45) - screen->randr = RR_Rotate_0; - else if (rotate < 135) - screen->randr = RR_Rotate_90; - else if (rotate < 225) - screen->randr = RR_Rotate_180; - else if (rotate < 315) - screen->randr = RR_Rotate_270; - else - screen->randr = RR_Rotate_0; - } - } - if (delim == 'X') { - arg = KdParseFindNext(arg, "xY", save, &delim); - screen->randr |= RR_Reflect_X; - } - - if (delim == 'Y') { - arg = KdParseFindNext(arg, "xY", save, &delim); - screen->randr |= RR_Reflect_Y; - } - - arg = KdParseFindNext(arg, "x/,", save, &delim); - if (save[0]) { - screen->fb.depth = atoi(save); - if (delim == '/') { - arg = KdParseFindNext(arg, "x,", save, &delim); - if (save[0]) - screen->fb.bitsPerPixel = atoi(save); - } - else - screen->fb.bitsPerPixel = 0; - } - - if (delim == 'x') { - arg = KdParseFindNext(arg, "x", save, &delim); - if (save[0]) - screen->rate = atoi(save); - } -} - -static void -KdParseRgba(char *rgba) -{ - if (!strcmp(rgba, "rgb")) - kdSubpixelOrder = SubPixelHorizontalRGB; - else if (!strcmp(rgba, "bgr")) - kdSubpixelOrder = SubPixelHorizontalBGR; - else if (!strcmp(rgba, "vrgb")) - kdSubpixelOrder = SubPixelVerticalRGB; - else if (!strcmp(rgba, "vbgr")) - kdSubpixelOrder = SubPixelVerticalBGR; - else if (!strcmp(rgba, "none")) - kdSubpixelOrder = SubPixelNone; - else - kdSubpixelOrder = SubPixelUnknown; -} - -void -KdUseMsg(void) -{ - ErrorF("\nTinyX Device Dependent Usage:\n"); - ErrorF - ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM][+[-]XOFFSET][+[-]YOFFSET][@ROTATION][X][Y][xDEPTH/BPP[xFREQ]] Specify screen characteristics\n"); - ErrorF - ("-rgba rgb/bgr/vrgb/vbgr/none Specify subpixel ordering for LCD panels\n"); - ErrorF - ("-mouse driver [,n,,options] Specify the pointer driver and its options (n is the number of buttons)\n"); - ErrorF - ("-keybd driver [,,options] Specify the keyboard driver and its options\n"); - ErrorF("-xkb-rules Set default XkbRules value (can be overridden by -keybd options)\n"); - ErrorF("-xkb-model Set default XkbModel value (can be overridden by -keybd options)\n"); - ErrorF("-xkb-layout Set default XkbLayout value (can be overridden by -keybd options)\n"); - ErrorF("-xkb-variant Set default XkbVariant value (can be overridden by -keybd options)\n"); - ErrorF("-xkb-options Set default XkbOptions value (can be overridden by -keybd options)\n"); - ErrorF("-zaphod Disable cursor screen switching\n"); - ErrorF("-2button Emulate 3 button mouse\n"); - ErrorF("-3button Disable 3 button mouse emulation\n"); - ErrorF - ("-rawcoord Don't transform pointer coordinates on rotation\n"); - ErrorF("-dumb Disable hardware acceleration\n"); - ErrorF("-softCursor Force software cursor\n"); - ErrorF("-videoTest Start the server, pause momentarily and exit\n"); - ErrorF - ("-origin X,Y Locates the next screen in the the virtual screen (Xinerama)\n"); - ErrorF("-switchCmd Command to execute on vt switch\n"); - ErrorF - ("vtxx Use virtual terminal xx instead of the next available\n"); -} - -int -KdProcessArgument(int argc, char **argv, int i) -{ - KdCardInfo *card; - KdScreenInfo *screen; - - if (!strcmp(argv[i], "-screen")) { - if ((i + 1) < argc) { - card = KdCardInfoLast(); - if (!card) { - InitCard(0); - card = KdCardInfoLast(); - } - if (card) { - screen = KdScreenInfoAdd(card); - KdParseScreen(screen, argv[i + 1]); - } - else - ErrorF("No matching card found!\n"); - } - else - UseMsg(); - return 2; - } - if (!strcmp(argv[i], "-zaphod")) { - kdDisableZaphod = TRUE; - return 1; - } - if (!strcmp(argv[i], "-3button")) { - kdEmulateMiddleButton = FALSE; - return 1; - } - if (!strcmp(argv[i], "-2button")) { - kdEmulateMiddleButton = TRUE; - return 1; - } - if (!strcmp(argv[i], "-rawcoord")) { - kdRawPointerCoordinates = 1; - return 1; - } - if (!strcmp(argv[i], "-dumb")) { - kdDumbDriver = TRUE; - return 1; - } - if (!strcmp(argv[i], "-softCursor")) { - kdSoftCursor = TRUE; - return 1; - } - if (!strcmp(argv[i], "-origin")) { - if ((i + 1) < argc) { - char *x = argv[i + 1]; - char *y = strchr(x, ','); - - if (x) - kdOrigin.x = atoi(x); - else - kdOrigin.x = 0; - if (y) - kdOrigin.y = atoi(y + 1); - else - kdOrigin.y = 0; - } - else - UseMsg(); - return 2; - } - if (!strcmp(argv[i], "-rgba")) { - if ((i + 1) < argc) - KdParseRgba(argv[i + 1]); - else - UseMsg(); - return 2; - } - if (!strcmp(argv[i], "-switchCmd")) { - if ((i + 1) < argc) - kdSwitchCmd = argv[i + 1]; - else - UseMsg(); - return 2; - } - if (!strcmp(argv[i], "-xkb-rules")) { - if (i + 1 >= argc) { - UseMsg(); - FatalError("Missing argument for option -xkb-rules.\n"); - } - kdGlobalXkbRules = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-xkb-model")) { - if (i + 1 >= argc) { - UseMsg(); - FatalError("Missing argument for option -xkb-model.\n"); - } - kdGlobalXkbModel = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-xkb-layout")) { - if (i + 1 >= argc) { - UseMsg(); - FatalError("Missing argument for option -xkb-layout.\n"); - } - kdGlobalXkbLayout = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-xkb-variant")) { - if (i + 1 >= argc) { - UseMsg(); - FatalError("Missing argument for option -xkb-variant.\n"); - } - kdGlobalXkbVariant = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-xkb-options")) { - if (i + 1 >= argc) { - UseMsg(); - FatalError("Missing argument for option -xkb-options.\n"); - } - kdGlobalXkbOptions = argv[i + 1]; - return 2; - } - if (!strcmp(argv[i], "-mouse") || !strcmp(argv[i], "-pointer")) { - if (i + 1 >= argc) - UseMsg(); - KdAddConfigPointer(argv[i + 1]); - kdHasPointer = TRUE; - return 2; - } - if (!strcmp(argv[i], "-keybd")) { - if (i + 1 >= argc) - UseMsg(); - KdAddConfigKeyboard(argv[i + 1]); - kdHasKbd = TRUE; - return 2; - } - - return 0; -} - -static Bool -KdAllocatePrivates(ScreenPtr pScreen) -{ - KdPrivScreenPtr pScreenPriv; - - if (kdGeneration != serverGeneration) - kdGeneration = serverGeneration; - - if (!dixRegisterPrivateKey(&kdScreenPrivateKeyRec, PRIVATE_SCREEN, 0)) - return FALSE; - - pScreenPriv = calloc(1, sizeof(*pScreenPriv)); - if (!pScreenPriv) - return FALSE; - KdSetScreenPriv(pScreen, pScreenPriv); - return TRUE; -} - -static Bool -KdCreateScreenResources(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdCardInfo *card = pScreenPriv->card; - Bool ret; - - pScreen->CreateScreenResources = pScreenPriv->CreateScreenResources; - if (pScreen->CreateScreenResources) - ret = (*pScreen->CreateScreenResources) (pScreen); - else - ret = -1; - pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = KdCreateScreenResources; - if (ret && card->cfuncs->createRes) - ret = (*card->cfuncs->createRes) (pScreen); - return ret; -} - -static Bool -KdCloseScreen(ScreenPtr pScreen) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - KdCardInfo *card = pScreenPriv->card; - Bool ret; - - if (card->cfuncs->closeScreen) - (*card->cfuncs->closeScreen)(pScreen); - - pScreenPriv->closed = TRUE; - pScreen->CloseScreen = pScreenPriv->CloseScreen; - - if (pScreen->CloseScreen) - ret = (*pScreen->CloseScreen) (pScreen); - else - ret = TRUE; - - if (screen->mynum == card->selected) - KdDisableScreen(pScreen); - - if (!pScreenPriv->screen->dumb && card->cfuncs->finiAccel) - (*card->cfuncs->finiAccel) (pScreen); - - if (card->cfuncs->scrfini) - (*card->cfuncs->scrfini) (screen); - - /* - * Clean up card when last screen is closed, DIX closes them in - * reverse order, thus we check for when the first in the list is closed - */ - if (screen == card->screenList) { - if (card->cfuncs->cardfini) - (*card->cfuncs->cardfini) (card); - /* - * Clean up OS when last card is closed - */ - if (card == kdCardInfo) { - kdEnabled = FALSE; - } - } - - pScreenPriv->screen->pScreen = 0; - - free((void *) pScreenPriv); - return ret; -} - -static Bool -KdSaveScreen(ScreenPtr pScreen, int on) -{ - return FALSE; -} - -static Bool -KdCreateWindow(WindowPtr pWin) -{ -#ifndef PHOENIX - if (!pWin->parent) { - KdScreenPriv(pWin->drawable.pScreen); - - if (!pScreenPriv->enabled) { - RegionEmpty(&pWin->borderClip); - RegionBreak(&pWin->clipList); - } - } -#endif - return fbCreateWindow(pWin); -} - -void -KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - int subpixel_order = screen->subpixel_order; - Rotation subpixel_dir; - int i; - - static struct { - int subpixel_order; - Rotation direction; - } orders[] = { - {SubPixelHorizontalRGB, RR_Rotate_0}, - {SubPixelHorizontalBGR, RR_Rotate_180}, - {SubPixelVerticalRGB, RR_Rotate_270}, - {SubPixelVerticalBGR, RR_Rotate_90}, - }; - - static struct { - int bit; - int normal; - int reflect; - } reflects[] = { - {RR_Reflect_X, SubPixelHorizontalRGB, SubPixelHorizontalBGR}, - {RR_Reflect_X, SubPixelHorizontalBGR, SubPixelHorizontalRGB}, - {RR_Reflect_Y, SubPixelVerticalRGB, SubPixelVerticalBGR}, - {RR_Reflect_Y, SubPixelVerticalRGB, SubPixelVerticalRGB}, - }; - - /* map subpixel to direction */ - for (i = 0; i < 4; i++) - if (orders[i].subpixel_order == subpixel_order) - break; - if (i < 4) { - subpixel_dir = - KdAddRotation(randr & RR_Rotate_All, orders[i].direction); - - /* map back to subpixel order */ - for (i = 0; i < 4; i++) - if (orders[i].direction & subpixel_dir) { - subpixel_order = orders[i].subpixel_order; - break; - } - /* reflect */ - for (i = 0; i < 4; i++) - if ((randr & reflects[i].bit) && - reflects[i].normal == subpixel_order) { - subpixel_order = reflects[i].reflect; - break; - } - } - PictureSetSubpixelOrder(pScreen, subpixel_order); -} - -/* Pass through AddScreen, which doesn't take any closure */ -static KdScreenInfo *kdCurrentScreen; - -static Bool -KdScreenInit(ScreenPtr pScreen, int argc, char **argv) -{ - KdScreenInfo *screen = kdCurrentScreen; - KdCardInfo *card = screen->card; - KdPrivScreenPtr pScreenPriv; - - /* - * note that screen->fb is set up for the nominal orientation - * of the screen; that means if randr is rotated, the values - * there should reflect a rotated frame buffer (or shadow). - */ - Bool rotated = (screen->randr & (RR_Rotate_90 | RR_Rotate_270)) != 0; - int width, height, *width_mmp, *height_mmp; - - KdAllocatePrivates(pScreen); - - pScreenPriv = KdGetScreenPriv(pScreen); - - if (!rotated) { - width = screen->width; - height = screen->height; - width_mmp = &screen->width_mm; - height_mmp = &screen->height_mm; - } - else { - width = screen->height; - height = screen->width; - width_mmp = &screen->height_mm; - height_mmp = &screen->width_mm; - } - screen->pScreen = pScreen; - pScreenPriv->screen = screen; - pScreenPriv->card = card; - pScreenPriv->bytesPerPixel = screen->fb.bitsPerPixel >> 3; - pScreenPriv->dpmsState = KD_DPMS_NORMAL; - pScreen->x = screen->origin.x; - pScreen->y = screen->origin.y; - - if (!monitorResolution) - monitorResolution = 75; - /* - * This is done in this order so that backing store wraps - * our GC functions; fbFinishScreenInit initializes MI - * backing store - */ - if (!fbSetupScreen(pScreen, - screen->fb.frameBuffer, - width, height, - monitorResolution, monitorResolution, - screen->fb.pixelStride, screen->fb.bitsPerPixel)) { - return FALSE; - } - - /* - * Set colormap functions - */ - pScreen->InstallColormap = KdInstallColormap; - pScreen->UninstallColormap = KdUninstallColormap; - pScreen->ListInstalledColormaps = KdListInstalledColormaps; - pScreen->StoreColors = KdStoreColors; - - pScreen->SaveScreen = KdSaveScreen; - pScreen->CreateWindow = KdCreateWindow; - - if (!fbFinishScreenInit(pScreen, - screen->fb.frameBuffer, - width, height, - monitorResolution, monitorResolution, - screen->fb.pixelStride, screen->fb.bitsPerPixel)) { - return FALSE; - } - - /* - * Fix screen sizes; for some reason mi takes dpi instead of mm. - * Rounding errors are annoying - */ - if (*width_mmp) - pScreen->mmWidth = *width_mmp; - else - *width_mmp = pScreen->mmWidth; - if (*height_mmp) - pScreen->mmHeight = *height_mmp; - else - *height_mmp = pScreen->mmHeight; - - /* - * Plug in our own block/wakeup handlers. - * miScreenInit installs NoopDDA in both places - */ - pScreen->BlockHandler = KdBlockHandler; - pScreen->WakeupHandler = KdWakeupHandler; - - if (!fbPictureInit(pScreen, 0, 0)) - return FALSE; - if (card->cfuncs->initScreen) - if (!(*card->cfuncs->initScreen) (pScreen)) - return FALSE; - - if (!screen->dumb && card->cfuncs->initAccel) - if (!(*card->cfuncs->initAccel) (pScreen)) - screen->dumb = TRUE; - - if (card->cfuncs->finishInitScreen) - if (!(*card->cfuncs->finishInitScreen) (pScreen)) - return FALSE; - - /* - * Wrap CloseScreen, the order now is: - * KdCloseScreen - * fbCloseScreen - */ - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = KdCloseScreen; - - pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = KdCreateScreenResources; - - if (screen->softCursor || - !card->cfuncs->initCursor || !(*card->cfuncs->initCursor) (pScreen)) { - /* Use MI for cursor display and event queueing. */ - screen->softCursor = TRUE; - miDCInitialize(pScreen, &kdPointerScreenFuncs); - } - - if (!fbCreateDefColormap(pScreen)) { - return FALSE; - } - - KdSetSubpixelOrder(pScreen, screen->randr); - - /* - * Enable the hardware - */ - kdEnabled = TRUE; - - if (screen->mynum == card->selected) { - pScreenPriv->enabled = TRUE; - KdEnableColormap(pScreen); - if (!screen->dumb && card->cfuncs->enableAccel) - (*card->cfuncs->enableAccel) (pScreen); - } - - return TRUE; -} - -static void -KdInitScreen(ScreenInfo * pScreenInfo, - KdScreenInfo * screen, int argc, char **argv) -{ - KdCardInfo *card = screen->card; - - if (!(*card->cfuncs->scrinit) (screen)) - FatalError("Screen initialization failed!\n"); - - if (!card->cfuncs->initAccel) - screen->dumb = TRUE; - if (!card->cfuncs->initCursor) - screen->softCursor = TRUE; -} - -static Bool -KdSetPixmapFormats(ScreenInfo * pScreenInfo) -{ - CARD8 depthToBpp[33]; /* depth -> bpp map */ - KdCardInfo *card; - KdScreenInfo *screen; - int i; - int bpp; - PixmapFormatRec *format; - - for (i = 1; i <= 32; i++) - depthToBpp[i] = 0; - - /* - * Generate mappings between bitsPerPixel and depth, - * also ensure that all screens comply with protocol - * restrictions on equivalent formats for the same - * depth on different screens - */ - for (card = kdCardInfo; card; card = card->next) { - for (screen = card->screenList; screen; screen = screen->next) { - bpp = screen->fb.bitsPerPixel; - if (bpp == 24) - bpp = 32; - if (!depthToBpp[screen->fb.depth]) - depthToBpp[screen->fb.depth] = bpp; - else if (depthToBpp[screen->fb.depth] != bpp) - return FALSE; - } - } - - /* - * Fill in additional formats - */ - for (i = 0; i < ARRAY_SIZE(kdDepths); i++) - if (!depthToBpp[kdDepths[i].depth]) - depthToBpp[kdDepths[i].depth] = kdDepths[i].bpp; - - pScreenInfo->imageByteOrder = IMAGE_BYTE_ORDER; - pScreenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; - pScreenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; - pScreenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; - - pScreenInfo->numPixmapFormats = 0; - - for (i = 1; i <= 32; i++) { - if (depthToBpp[i]) { - format = &pScreenInfo->formats[pScreenInfo->numPixmapFormats++]; - format->depth = i; - format->bitsPerPixel = depthToBpp[i]; - format->scanlinePad = BITMAP_SCANLINE_PAD; - } - } - - return TRUE; -} - -static void -KdAddScreen(ScreenInfo * pScreenInfo, - KdScreenInfo * screen, int argc, char **argv) -{ - int i; - - /* - * Fill in fb visual type masks for this screen - */ - for (i = 0; i < pScreenInfo->numPixmapFormats; i++) { - unsigned long visuals; - Pixel rm, gm, bm; - - visuals = 0; - rm = gm = bm = 0; - if (pScreenInfo->formats[i].depth == screen->fb.depth) { - visuals = screen->fb.visuals; - rm = screen->fb.redMask; - gm = screen->fb.greenMask; - bm = screen->fb.blueMask; - } - fbSetVisualTypesAndMasks(pScreenInfo->formats[i].depth, - visuals, 8, rm, gm, bm); - } - - kdCurrentScreen = screen; - - AddScreen(KdScreenInit, argc, argv); -} - -void -KdInitOutput(ScreenInfo * pScreenInfo, int argc, char **argv) -{ - KdCardInfo *card; - KdScreenInfo *screen; - - if (!kdCardInfo) { - InitCard(0); - if (!(card = KdCardInfoLast())) - FatalError("No matching cards found!\n"); - screen = KdScreenInfoAdd(card); - KdParseScreen(screen, 0); - } - /* - * Initialize all of the screens for all of the cards - */ - for (card = kdCardInfo; card; card = card->next) { - int ret = 1; - - if (card->cfuncs->cardinit) - ret = (*card->cfuncs->cardinit) (card); - if (ret) { - for (screen = card->screenList; screen; screen = screen->next) - KdInitScreen(pScreenInfo, screen, argc, argv); - } - } - - /* - * Merge the various pixmap formats together, this can fail - * when two screens share depth but not bitsPerPixel - */ - if (!KdSetPixmapFormats(pScreenInfo)) - return; - - /* - * Add all of the screens - */ - for (card = kdCardInfo; card; card = card->next) - for (screen = card->screenList; screen; screen = screen->next) - KdAddScreen(pScreenInfo, screen, argc, argv); - - xorgGlxCreateVendor(); - -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - if (SeatId) /* Enable input hot-plugging */ - config_pre_init(); -#endif -} - -void -OsVendorFatalError(const char *f, va_list args) -{ -} - -/* These stubs can be safely removed once we can - * split input and GPU parts in hotplug.h et al. */ -#ifdef CONFIG_UDEV_KMS -void -NewGPUDeviceRequest(struct OdevAttributes *attribs) -{ -} - -void -DeleteGPUDeviceRequest(struct OdevAttributes *attribs) -{ -} -#endif - -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) -struct xf86_platform_device * -xf86_find_platform_device_by_devnum(int major, int minor) -{ - return NULL; -} -#endif - -#ifdef SYSTEMD_LOGIND -void -systemd_logind_vtenter(void) -{ -} - -void -systemd_logind_release_fd(int major, int minor, int fd) -{ - close(fd); -} -#endif diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h deleted file mode 100644 index 432f89140..000000000 --- a/hw/kdrive/src/kdrive.h +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright © 1999 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _KDRIVE_H_ -#define _KDRIVE_H_ - -#include -#include -#include -#include -#include -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "windowstr.h" -#include "servermd.h" -#include "colormapst.h" -#include "gcstruct.h" -#include "input.h" -#include "mipointer.h" -#include "mi.h" -#include "dix.h" -#include "fb.h" -#include "fboverlay.h" -#include "shadow.h" -#include "randrstr.h" -#include "globals.h" - -#include "xkbstr.h" - -#define KD_DPMS_NORMAL 0 -#define KD_DPMS_STANDBY 1 -#define KD_DPMS_SUSPEND 2 -#define KD_DPMS_POWERDOWN 3 -#define KD_DPMS_MAX KD_DPMS_POWERDOWN - -#define Status int - -typedef struct _KdCardInfo { - struct _KdCardFuncs *cfuncs; - void *closure; - void *driver; - struct _KdScreenInfo *screenList; - int selected; - struct _KdCardInfo *next; -} KdCardInfo; - -extern KdCardInfo *kdCardInfo; - -/* - * Configuration information per X screen - */ -typedef struct _KdFrameBuffer { - CARD8 *frameBuffer; - int depth; - int bitsPerPixel; - int pixelStride; - int byteStride; - Bool shadow; - unsigned long visuals; - Pixel redMask, greenMask, blueMask; - void *closure; -} KdFrameBuffer; - -#define RR_Rotate_All (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270) -#define RR_Reflect_All (RR_Reflect_X|RR_Reflect_Y) - -typedef struct _KdScreenInfo { - struct _KdScreenInfo *next; - KdCardInfo *card; - ScreenPtr pScreen; - void *driver; - Rotation randr; /* rotation and reflection */ - int x; - int y; - int width; - int height; - int rate; - int width_mm; - int height_mm; - int subpixel_order; - Bool dumb; - Bool softCursor; - int mynum; - DDXPointRec origin; - KdFrameBuffer fb; -} KdScreenInfo; - -typedef struct _KdCardFuncs { - Bool (*cardinit) (KdCardInfo *); /* detect and map device */ - Bool (*scrinit) (KdScreenInfo *); /* initialize screen information */ - Bool (*initScreen) (ScreenPtr); /* initialize ScreenRec */ - Bool (*finishInitScreen) (ScreenPtr pScreen); - Bool (*createRes) (ScreenPtr); /* create screen resources */ - void (*scrfini) (KdScreenInfo *); /* close down screen */ - void (*cardfini) (KdCardInfo *); /* close down */ - - Bool (*initCursor) (ScreenPtr); /* detect and map cursor */ - - Bool (*initAccel) (ScreenPtr); - void (*enableAccel) (ScreenPtr); - void (*disableAccel) (ScreenPtr); - void (*finiAccel) (ScreenPtr); - - void (*getColors) (ScreenPtr, int, xColorItem *); - void (*putColors) (ScreenPtr, int, xColorItem *); - - void (*closeScreen) (ScreenPtr); /* close ScreenRec */ -} KdCardFuncs; - -#define KD_MAX_PSEUDO_DEPTH 8 -#define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH) - -typedef struct { - KdScreenInfo *screen; - KdCardInfo *card; - - Bool enabled; - Bool closed; - int bytesPerPixel; - - int dpmsState; - - ColormapPtr pInstalledmap; /* current colormap */ - xColorItem systemPalette[KD_MAX_PSEUDO_SIZE]; /* saved windows colors */ - - CreateScreenResourcesProcPtr CreateScreenResources; - CloseScreenProcPtr CloseScreen; -} KdPrivScreenRec, *KdPrivScreenPtr; - -typedef enum _kdPointerState { - start, - button_1_pend, - button_1_down, - button_2_down, - button_3_pend, - button_3_down, - synth_2_down_13, - synth_2_down_3, - synth_2_down_1, - num_input_states -} KdPointerState; - -#define KD_MAX_BUTTON 32 - -#define KD_KEYBOARD 1 -#define KD_MOUSE 2 -#define KD_TOUCHSCREEN 3 - -typedef struct _KdPointerInfo KdPointerInfo; - -typedef struct _KdPointerDriver { - const char *name; - Status(*Init) (KdPointerInfo *); - Status(*Enable) (KdPointerInfo *); - void (*Disable) (KdPointerInfo *); - void (*Fini) (KdPointerInfo *); - struct _KdPointerDriver *next; -} KdPointerDriver; - -struct _KdPointerInfo { - DeviceIntPtr dixdev; - char *name; - char *path; - char *protocol; - InputOption *options; - int inputClass; - - CARD8 map[KD_MAX_BUTTON + 1]; - int nButtons; - int nAxes; - - Bool emulateMiddleButton; - unsigned long emulationTimeout; - int emulationDx, emulationDy; - - Bool timeoutPending; - KdPointerState mouseState; - Bool eventHeld; - struct { - int type; - int x; - int y; - int z; - int flags; - int absrel; - } heldEvent; - unsigned char buttonState; - Bool transformCoordinates; - int pressureThreshold; - - KdPointerDriver *driver; - void *driverPrivate; - - struct _KdPointerInfo *next; -}; - -void KdAddPointerDriver(KdPointerDriver * driver); -void KdRemovePointerDriver(KdPointerDriver * driver); -KdPointerInfo *KdNewPointer(void); -void KdFreePointer(KdPointerInfo *); -int KdAddPointer(KdPointerInfo * ki); -int KdAddConfigPointer(char *pointer); -void KdRemovePointer(KdPointerInfo * ki); - -#define KD_KEY_COUNT 248 -#define KD_MIN_KEYCODE 8 -#define KD_MAX_KEYCODE 255 -#define KD_MAX_WIDTH 4 -#define KD_MAX_LENGTH (KD_MAX_KEYCODE - KD_MIN_KEYCODE + 1) - -typedef struct { - KeySym modsym; - int modbit; -} KdKeySymModsRec; - -typedef struct _KdKeyboardInfo KdKeyboardInfo; - -typedef struct _KdKeyboardDriver { - const char *name; - Bool (*Init) (KdKeyboardInfo *); - Bool (*Enable) (KdKeyboardInfo *); - void (*Leds) (KdKeyboardInfo *, int); - void (*Bell) (KdKeyboardInfo *, int, int, int); - void (*Disable) (KdKeyboardInfo *); - void (*Fini) (KdKeyboardInfo *); - struct _KdKeyboardDriver *next; -} KdKeyboardDriver; - -struct _KdKeyboardInfo { - struct _KdKeyboardInfo *next; - DeviceIntPtr dixdev; - void *closure; - char *name; - char *path; - int inputClass; - char *xkbRules; - char *xkbModel; - char *xkbLayout; - char *xkbVariant; - char *xkbOptions; - int LockLed; - - int minScanCode; - int maxScanCode; - - int leds; - int bellPitch; - int bellDuration; - InputOption *options; - - KdKeyboardDriver *driver; - void *driverPrivate; -}; - -void KdAddKeyboardDriver(KdKeyboardDriver * driver); -void KdRemoveKeyboardDriver(KdKeyboardDriver * driver); -KdKeyboardInfo *KdNewKeyboard(void); -void KdFreeKeyboard(KdKeyboardInfo * ki); -int KdAddConfigKeyboard(char *pointer); -int KdAddKeyboard(KdKeyboardInfo * ki); -void KdRemoveKeyboard(KdKeyboardInfo * ki); - -typedef struct _KdPointerMatrix { - int matrix[2][3]; -} KdPointerMatrix; - -extern DevPrivateKeyRec kdScreenPrivateKeyRec; - -#define kdScreenPrivateKey (&kdScreenPrivateKeyRec) - -extern Bool kdEmulateMiddleButton; -extern Bool kdDisableZaphod; - -#define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \ - dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey)) -#define KdSetScreenPriv(pScreen,v) \ - dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v) -#define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen) - -/* kcmap.c */ -void - KdEnableColormap(ScreenPtr pScreen); - -void - KdDisableColormap(ScreenPtr pScreen); - -void - KdInstallColormap(ColormapPtr pCmap); - -void - KdUninstallColormap(ColormapPtr pCmap); - -int - KdListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmaps); - -void - KdStoreColors(ColormapPtr pCmap, int ndef, xColorItem * pdefs); - -/* kdrive.c */ -extern miPointerScreenFuncRec kdPointerScreenFuncs; - -void - KdDisableScreen(ScreenPtr pScreen); - -Bool - KdEnableScreen(ScreenPtr pScreen); - -void - KdEnableScreens(void); - -void - KdProcessSwitch(void); - -Rotation KdAddRotation(Rotation a, Rotation b); - -Rotation KdSubRotation(Rotation a, Rotation b); - -void - KdParseScreen(KdScreenInfo * screen, const char *arg); - -const char * -KdParseFindNext(const char *cur, const char *delim, char *save, char *last); - -void - KdUseMsg(void); - -int - KdProcessArgument(int argc, char **argv, int i); - -void - KdOsAddInputDrivers(void); - -void - KdInitCard(ScreenInfo * pScreenInfo, KdCardInfo * card, int argc, char **argv); - -void - KdInitOutput(ScreenInfo * pScreenInfo, int argc, char **argv); - -void - KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr); - -void - KdBacktrace(int signum); - -/* kinfo.c */ -KdCardInfo *KdCardInfoAdd(KdCardFuncs * funcs, void *closure); - -KdCardInfo *KdCardInfoLast(void); - -void - KdCardInfoDispose(KdCardInfo * ci); - -KdScreenInfo *KdScreenInfoAdd(KdCardInfo * ci); - -void - KdScreenInfoDispose(KdScreenInfo * si); - -/* kinput.c */ -void - KdInitInput(void); -void - KdCloseInput(void); - -void -KdEnqueueKeyboardEvent(KdKeyboardInfo * ki, unsigned char scan_code, - unsigned char is_up); - -#define KD_BUTTON_1 0x01 -#define KD_BUTTON_2 0x02 -#define KD_BUTTON_3 0x04 -#define KD_BUTTON_4 0x08 -#define KD_BUTTON_5 0x10 -#define KD_BUTTON_8 0x80 -#define KD_POINTER_DESKTOP 0x40000000 -#define KD_MOUSE_DELTA 0x80000000 - -void -KdEnqueuePointerEvent(KdPointerInfo * pi, unsigned long flags, int rx, int ry, - int rz); - -void - KdSetPointerMatrix(KdPointerMatrix *pointer); - -void -KdComputePointerMatrix(KdPointerMatrix *pointer, Rotation randr, int width, - int height); - -void -KdBlockHandler(ScreenPtr pScreen, void *timeout); - -void -KdWakeupHandler(ScreenPtr pScreen, int result); - -void - KdDisableInput(void); - -void - KdEnableInput(void); - -/* kshadow.c */ -Bool - KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate); - -void - KdShadowFbFree(KdScreenInfo * screen); - -Bool - -KdShadowSet(ScreenPtr pScreen, int randr, ShadowUpdateProc update, - ShadowWindowProc window); - -void - KdShadowUnset(ScreenPtr pScreen); - -/* function prototypes to be implemented by the drivers */ -void - InitCard(char *name); - -#endif /* _KDRIVE_H_ */ diff --git a/hw/kdrive/src/kinfo.c b/hw/kdrive/src/kinfo.c deleted file mode 100644 index 4abb082b0..000000000 --- a/hw/kdrive/src/kinfo.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright © 1999 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "kdrive.h" - -KdCardInfo *kdCardInfo; - -KdCardInfo * -KdCardInfoAdd(KdCardFuncs * funcs, void *closure) -{ - KdCardInfo *ci, **prev; - - ci = calloc(1, sizeof(KdCardInfo)); - if (!ci) - return 0; - for (prev = &kdCardInfo; *prev; prev = &(*prev)->next); - *prev = ci; - ci->cfuncs = funcs; - ci->closure = closure; - ci->screenList = 0; - ci->selected = 0; - ci->next = 0; - return ci; -} - -KdCardInfo * -KdCardInfoLast(void) -{ - KdCardInfo *ci; - - if (!kdCardInfo) - return 0; - for (ci = kdCardInfo; ci->next; ci = ci->next); - return ci; -} - -void -KdCardInfoDispose(KdCardInfo * ci) -{ - KdCardInfo **prev; - - for (prev = &kdCardInfo; *prev; prev = &(*prev)->next) - if (*prev == ci) { - *prev = ci->next; - free(ci); - break; - } -} - -KdScreenInfo * -KdScreenInfoAdd(KdCardInfo * ci) -{ - KdScreenInfo *si, **prev; - int n; - - si = calloc(1, sizeof(KdScreenInfo)); - if (!si) - return 0; - for (prev = &ci->screenList, n = 0; *prev; prev = &(*prev)->next, n++); - *prev = si; - si->next = 0; - si->card = ci; - si->mynum = n; - return si; -} - -void -KdScreenInfoDispose(KdScreenInfo * si) -{ - KdCardInfo *ci = si->card; - KdScreenInfo **prev; - - for (prev = &ci->screenList; *prev; prev = &(*prev)->next) { - if (*prev == si) { - *prev = si->next; - free(si); - if (!ci->screenList) - KdCardInfoDispose(ci); - break; - } - } -} - -KdPointerInfo * -KdNewPointer(void) -{ - KdPointerInfo *pi; - int i; - - pi = (KdPointerInfo *) calloc(1, sizeof(KdPointerInfo)); - if (!pi) - return NULL; - - pi->name = strdup("Generic Pointer"); - pi->path = NULL; - pi->inputClass = KD_MOUSE; - pi->driver = NULL; - pi->driverPrivate = NULL; - pi->next = NULL; - pi->options = NULL; - pi->nAxes = 3; - pi->nButtons = KD_MAX_BUTTON; - for (i = 1; i < KD_MAX_BUTTON; i++) - pi->map[i] = i; - - return pi; -} - -void -KdFreePointer(KdPointerInfo * pi) -{ - free(pi->name); - free(pi->path); - input_option_free_list(&pi->options); - pi->next = NULL; - free(pi); -} - -void -KdFreeKeyboard(KdKeyboardInfo * ki) -{ - free(ki->name); - free(ki->path); - free(ki->xkbRules); - free(ki->xkbModel); - free(ki->xkbLayout); - free(ki->xkbVariant); - free(ki->xkbOptions); - input_option_free_list(&ki->options); - ki->next = NULL; - free(ki); -} diff --git a/hw/kdrive/src/kinput.c b/hw/kdrive/src/kinput.c deleted file mode 100644 index 185a9a359..000000000 --- a/hw/kdrive/src/kinput.c +++ /dev/null @@ -1,2082 +0,0 @@ -/* - * Copyright © 1999 Keith Packard - * Copyright © 2006 Nokia Corporation - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of the authors not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. The authors make no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#include -#endif -#include "kdrive.h" -#include "inputstr.h" - -#define XK_PUBLISHING -#include -#if HAVE_X11_XF86KEYSYM_H -#include -#endif -#include -#ifdef __sun -#include /* needed for FNONBLOCK & FASYNC */ -#endif - -#include "xkbsrv.h" - -#include -#include -#include "XIstubs.h" /* even though we don't use stubs. cute, no? */ -#include "exevents.h" -#include "extinit.h" -#include "exglobals.h" -#include "eventstr.h" -#include "xserver-properties.h" -#include "inpututils.h" -#include "optionstr.h" - -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) -#include -#endif - -#define AtomFromName(x) MakeAtom(x, strlen(x), 1) - -struct KdConfigDevice { - char *line; - struct KdConfigDevice *next; -}; - -/* kdKeyboards and kdPointers hold all the real devices. */ -static KdKeyboardInfo *kdKeyboards = NULL; -static KdPointerInfo *kdPointers = NULL; -static struct KdConfigDevice *kdConfigKeyboards = NULL; -static struct KdConfigDevice *kdConfigPointers = NULL; - -static KdKeyboardDriver *kdKeyboardDrivers = NULL; -static KdPointerDriver *kdPointerDrivers = NULL; - -static Bool kdInputEnabled; -static Bool kdOffScreen; -static unsigned long kdOffScreenTime; - -static KdPointerMatrix kdPointerMatrix = { - {{1, 0, 0}, - {0, 1, 0}} -}; - -extern Bool kdRawPointerCoordinates; - -extern const char *kdGlobalXkbRules; -extern const char *kdGlobalXkbModel; -extern const char *kdGlobalXkbLayout; -extern const char *kdGlobalXkbVariant; -extern const char *kdGlobalXkbOptions; - -#ifdef FNONBLOCK -#define NOBLOCK FNONBLOCK -#else -#define NOBLOCK FNDELAY -#endif - -static void -KdResetInputMachine(void) -{ - KdPointerInfo *pi; - - for (pi = kdPointers; pi; pi = pi->next) { - pi->mouseState = start; - pi->eventHeld = FALSE; - } -} - -void -KdDisableInput(void) -{ - KdKeyboardInfo *ki; - KdPointerInfo *pi; - - input_lock(); - - for (ki = kdKeyboards; ki; ki = ki->next) { - if (ki->driver && ki->driver->Disable) - (*ki->driver->Disable) (ki); - } - - for (pi = kdPointers; pi; pi = pi->next) { - if (pi->driver && pi->driver->Disable) - (*pi->driver->Disable) (pi); - } - - kdInputEnabled = FALSE; -} - -void -KdEnableInput(void) -{ - InternalEvent ev; - KdKeyboardInfo *ki; - KdPointerInfo *pi; - - kdInputEnabled = TRUE; - - ev.any.time = GetTimeInMillis(); - - for (ki = kdKeyboards; ki; ki = ki->next) { - if (ki->driver && ki->driver->Enable) - (*ki->driver->Enable) (ki); - /* reset screen saver */ - NoticeEventTime (&ev, ki->dixdev); - } - - for (pi = kdPointers; pi; pi = pi->next) { - if (pi->driver && pi->driver->Enable) - (*pi->driver->Enable) (pi); - /* reset screen saver */ - NoticeEventTime (&ev, pi->dixdev); - } - - input_unlock(); -} - -static KdKeyboardDriver * -KdFindKeyboardDriver(const char *name) -{ - KdKeyboardDriver *ret; - - /* ask a stupid question ... */ - if (!name) - return NULL; - - for (ret = kdKeyboardDrivers; ret; ret = ret->next) { - if (strcmp(ret->name, name) == 0) - return ret; - } - - return NULL; -} - -static KdPointerDriver * -KdFindPointerDriver(const char *name) -{ - KdPointerDriver *ret; - - /* ask a stupid question ... */ - if (!name) - return NULL; - - for (ret = kdPointerDrivers; ret; ret = ret->next) { - if (strcmp(ret->name, name) == 0) - return ret; - } - - return NULL; -} - -static int -KdPointerProc(DeviceIntPtr pDevice, int onoff) -{ - DevicePtr pDev = (DevicePtr) pDevice; - KdPointerInfo *pi; - Atom xiclass; - Atom *btn_labels; - Atom *axes_labels; - - if (!pDev) - return BadImplementation; - - for (pi = kdPointers; pi; pi = pi->next) { - if (pi->dixdev && pi->dixdev->id == pDevice->id) - break; - } - - if (!pi || !pi->dixdev || pi->dixdev->id != pDevice->id) { - ErrorF("[KdPointerProc] Failed to find pointer for device %d!\n", - pDevice->id); - return BadImplementation; - } - - switch (onoff) { - case DEVICE_INIT: -#ifdef DEBUG - ErrorF("initialising pointer %s ...\n", pi->name); -#endif - if (!pi->driver) { - if (!pi->driverPrivate) { - ErrorF("no driver specified for pointer device \"%s\" (%s)\n", - pi->name ? pi->name : "(unnamed)", pi->path); - return BadImplementation; - } - - pi->driver = KdFindPointerDriver(pi->driverPrivate); - if (!pi->driver) { - ErrorF("Couldn't find pointer driver %s\n", - pi->driverPrivate ? (char *) pi->driverPrivate : - "(unnamed)"); - return !Success; - } - free(pi->driverPrivate); - pi->driverPrivate = NULL; - } - - if (!pi->driver->Init) { - ErrorF("no init function\n"); - return BadImplementation; - } - - if ((*pi->driver->Init) (pi) != Success) { - return !Success; - } - - btn_labels = calloc(pi->nButtons, sizeof(Atom)); - if (!btn_labels) - return BadAlloc; - axes_labels = calloc(pi->nAxes, sizeof(Atom)); - if (!axes_labels) { - free(btn_labels); - return BadAlloc; - } - - switch (pi->nAxes) { - default: - case 7: - btn_labels[6] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_RIGHT); - case 6: - btn_labels[5] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_HWHEEL_LEFT); - case 5: - btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN); - case 4: - btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP); - case 3: - btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT); - case 2: - btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE); - case 1: - btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT); - case 0: - break; - } - - if (pi->nAxes >= 2) { - axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); - axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); - } - - InitPointerDeviceStruct(pDev, pi->map, pi->nButtons, btn_labels, - (PtrCtrlProcPtr) NoopDDA, - GetMotionHistorySize(), pi->nAxes, axes_labels); - - free(btn_labels); - free(axes_labels); - - if (pi->inputClass == KD_TOUCHSCREEN) { - xiclass = AtomFromName(XI_TOUCHSCREEN); - } - else { - xiclass = AtomFromName(XI_MOUSE); - } - - AssignTypeAndName(pi->dixdev, xiclass, - pi->name ? pi->name : "Generic KDrive Pointer"); - - return Success; - - case DEVICE_ON: - if (pDev->on == TRUE) - return Success; - - if (!pi->driver->Enable) { - ErrorF("no enable function\n"); - return BadImplementation; - } - - if ((*pi->driver->Enable) (pi) == Success) { - pDev->on = TRUE; - return Success; - } - else { - return BadImplementation; - } - - return Success; - - case DEVICE_OFF: - if (pDev->on == FALSE) { - return Success; - } - - if (!pi->driver->Disable) { - return BadImplementation; - } - else { - (*pi->driver->Disable) (pi); - pDev->on = FALSE; - return Success; - } - - return Success; - - case DEVICE_CLOSE: - if (pDev->on) { - if (!pi->driver->Disable) { - return BadImplementation; - } - (*pi->driver->Disable) (pi); - pDev->on = FALSE; - } - - if (!pi->driver->Fini) - return BadImplementation; - - (*pi->driver->Fini) (pi); - - KdRemovePointer(pi); - - return Success; - } - - /* NOTREACHED */ - return BadImplementation; -} - -static void -KdRingBell(KdKeyboardInfo * ki, int volume, int pitch, int duration) -{ - if (!ki || !ki->driver || !ki->driver->Bell) - return; - - if (kdInputEnabled) - (*ki->driver->Bell) (ki, volume, pitch, duration); -} - -static void -KdBell(int volume, DeviceIntPtr pDev, void *arg, int something) -{ - KeybdCtrl *ctrl = arg; - KdKeyboardInfo *ki = NULL; - - for (ki = kdKeyboards; ki; ki = ki->next) { - if (ki->dixdev && ki->dixdev->id == pDev->id) - break; - } - - if (!ki || !ki->dixdev || ki->dixdev->id != pDev->id || !ki->driver) - return; - - KdRingBell(ki, volume, ctrl->bell_pitch, ctrl->bell_duration); -} - -void -DDXRingBell(int volume, int pitch, int duration) -{ - KdKeyboardInfo *ki = NULL; - - for (ki = kdKeyboards; ki; ki = ki->next) { - if (ki->dixdev->coreEvents) - KdRingBell(ki, volume, pitch, duration); - } -} - -static void -KdSetLeds(KdKeyboardInfo * ki, int leds) -{ - if (!ki || !ki->driver) - return; - - if (kdInputEnabled) { - if (ki->driver->Leds) - (*ki->driver->Leds) (ki, leds); - } -} - -static void -KdSetLed(KdKeyboardInfo * ki, int led, Bool on) -{ - if (!ki || !ki->dixdev || !ki->dixdev->kbdfeed) - return; - - NoteLedState(ki->dixdev, led, on); - KdSetLeds(ki, ki->dixdev->kbdfeed->ctrl.leds); -} - -void -KdSetPointerMatrix(KdPointerMatrix * matrix) -{ - kdPointerMatrix = *matrix; -} - -void -KdComputePointerMatrix(KdPointerMatrix * m, Rotation randr, int width, - int height) -{ - int x_dir = 1, y_dir = 1; - int i, j; - int size[2]; - - size[0] = width; - size[1] = height; - if (randr & RR_Reflect_X) - x_dir = -1; - if (randr & RR_Reflect_Y) - y_dir = -1; - switch (randr & (RR_Rotate_All)) { - case RR_Rotate_0: - m->matrix[0][0] = x_dir; - m->matrix[0][1] = 0; - m->matrix[1][0] = 0; - m->matrix[1][1] = y_dir; - break; - case RR_Rotate_90: - m->matrix[0][0] = 0; - m->matrix[0][1] = -x_dir; - m->matrix[1][0] = y_dir; - m->matrix[1][1] = 0; - break; - case RR_Rotate_180: - m->matrix[0][0] = -x_dir; - m->matrix[0][1] = 0; - m->matrix[1][0] = 0; - m->matrix[1][1] = -y_dir; - break; - case RR_Rotate_270: - m->matrix[0][0] = 0; - m->matrix[0][1] = x_dir; - m->matrix[1][0] = -y_dir; - m->matrix[1][1] = 0; - break; - } - for (i = 0; i < 2; i++) { - m->matrix[i][2] = 0; - for (j = 0; j < 2; j++) - if (m->matrix[i][j] < 0) - m->matrix[i][2] = size[j] - 1; - } -} - -static void -KdKbdCtrl(DeviceIntPtr pDevice, KeybdCtrl * ctrl) -{ - KdKeyboardInfo *ki; - - for (ki = kdKeyboards; ki; ki = ki->next) { - if (ki->dixdev && ki->dixdev->id == pDevice->id) - break; - } - - if (!ki || !ki->dixdev || ki->dixdev->id != pDevice->id || !ki->driver) - return; - - KdSetLeds(ki, ctrl->leds); - ki->bellPitch = ctrl->bell_pitch; - ki->bellDuration = ctrl->bell_duration; -} - -static int -KdKeyboardProc(DeviceIntPtr pDevice, int onoff) -{ - Bool ret; - DevicePtr pDev = (DevicePtr) pDevice; - KdKeyboardInfo *ki; - Atom xiclass; - XkbRMLVOSet rmlvo; - - if (!pDev) - return BadImplementation; - - for (ki = kdKeyboards; ki; ki = ki->next) { - if (ki->dixdev && ki->dixdev->id == pDevice->id) - break; - } - - if (!ki || !ki->dixdev || ki->dixdev->id != pDevice->id) { - return BadImplementation; - } - - switch (onoff) { - case DEVICE_INIT: -#ifdef DEBUG - ErrorF("initialising keyboard %s\n", ki->name); -#endif - if (!ki->driver) { - if (!ki->driverPrivate) { - ErrorF("no driver specified for keyboard device \"%s\" (%s)\n", - ki->name ? ki->name : "(unnamed)", ki->path); - return BadImplementation; - } - - ki->driver = KdFindKeyboardDriver(ki->driverPrivate); - if (!ki->driver) { - ErrorF("Couldn't find keyboard driver %s\n", - ki->driverPrivate ? (char *) ki->driverPrivate : - "(unnamed)"); - return !Success; - } - free(ki->driverPrivate); - ki->driverPrivate = NULL; - } - - if (!ki->driver->Init) { - ErrorF("Keyboard %s: no init function\n", ki->name); - return BadImplementation; - } - - memset(&rmlvo, 0, sizeof(rmlvo)); - rmlvo.rules = ki->xkbRules; - rmlvo.model = ki->xkbModel; - rmlvo.layout = ki->xkbLayout; - rmlvo.variant = ki->xkbVariant; - rmlvo.options = ki->xkbOptions; - ret = InitKeyboardDeviceStruct(pDevice, &rmlvo, KdBell, KdKbdCtrl); - if (!ret) { - ErrorF("Couldn't initialise keyboard %s\n", ki->name); - return BadImplementation; - } - - if ((*ki->driver->Init) (ki) != Success) { - return !Success; - } - - xiclass = AtomFromName(XI_KEYBOARD); - AssignTypeAndName(pDevice, xiclass, - ki->name ? ki->name : "Generic KDrive Keyboard"); - - KdResetInputMachine(); - - return Success; - - case DEVICE_ON: - if (pDev->on == TRUE) - return Success; - - if (!ki->driver->Enable) - return BadImplementation; - - if ((*ki->driver->Enable) (ki) != Success) { - return BadMatch; - } - - pDev->on = TRUE; - return Success; - - case DEVICE_OFF: - if (pDev->on == FALSE) - return Success; - - if (!ki->driver->Disable) - return BadImplementation; - - (*ki->driver->Disable) (ki); - pDev->on = FALSE; - - return Success; - - break; - - case DEVICE_CLOSE: - if (pDev->on) { - if (!ki->driver->Disable) - return BadImplementation; - - (*ki->driver->Disable) (ki); - pDev->on = FALSE; - } - - if (!ki->driver->Fini) - return BadImplementation; - - (*ki->driver->Fini) (ki); - - KdRemoveKeyboard(ki); - - return Success; - } - - /* NOTREACHED */ - return BadImplementation; -} - -void -KdAddPointerDriver(KdPointerDriver * driver) -{ - KdPointerDriver **prev; - - if (!driver) - return; - - for (prev = &kdPointerDrivers; *prev; prev = &(*prev)->next) { - if (*prev == driver) - return; - } - *prev = driver; -} - -void -KdRemovePointerDriver(KdPointerDriver * driver) -{ - KdPointerDriver *tmp; - - if (!driver) - return; - - /* FIXME remove all pointers using this driver */ - for (tmp = kdPointerDrivers; tmp; tmp = tmp->next) { - if (tmp->next == driver) - tmp->next = driver->next; - } - if (tmp == driver) - tmp = NULL; -} - -void -KdAddKeyboardDriver(KdKeyboardDriver * driver) -{ - KdKeyboardDriver **prev; - - if (!driver) - return; - - for (prev = &kdKeyboardDrivers; *prev; prev = &(*prev)->next) { - if (*prev == driver) - return; - } - *prev = driver; -} - -void -KdRemoveKeyboardDriver(KdKeyboardDriver * driver) -{ - KdKeyboardDriver *tmp; - - if (!driver) - return; - - /* FIXME remove all keyboards using this driver */ - for (tmp = kdKeyboardDrivers; tmp; tmp = tmp->next) { - if (tmp->next == driver) - tmp->next = driver->next; - } - if (tmp == driver) - tmp = NULL; -} - -KdKeyboardInfo * -KdNewKeyboard(void) -{ - KdKeyboardInfo *ki = calloc(sizeof(KdKeyboardInfo), 1); - - if (!ki) - return NULL; - - ki->minScanCode = 0; - ki->maxScanCode = 0; - ki->leds = 0; - ki->bellPitch = 1000; - ki->bellDuration = 200; - ki->next = NULL; - ki->options = NULL; - ki->name = strdup("Generic Keyboard"); - ki->path = NULL; - ki->xkbRules = strdup(kdGlobalXkbRules ? kdGlobalXkbRules : XKB_DFLT_RULES); - ki->xkbModel = strdup(kdGlobalXkbModel ? kdGlobalXkbModel : XKB_DFLT_MODEL); - ki->xkbLayout = strdup(kdGlobalXkbLayout ? kdGlobalXkbLayout : XKB_DFLT_LAYOUT); - ki->xkbVariant = strdup(kdGlobalXkbVariant ? kdGlobalXkbVariant :XKB_DFLT_VARIANT); - ki->xkbOptions = strdup(kdGlobalXkbOptions ? kdGlobalXkbOptions : XKB_DFLT_OPTIONS); - - return ki; -} - -int -KdAddConfigKeyboard(char *keyboard) -{ - struct KdConfigDevice **prev, *new; - - if (!keyboard) - return Success; - - new = (struct KdConfigDevice *) calloc(sizeof(struct KdConfigDevice), 1); - if (!new) - return BadAlloc; - - new->line = strdup(keyboard); - new->next = NULL; - - for (prev = &kdConfigKeyboards; *prev; prev = &(*prev)->next); - *prev = new; - - return Success; -} - -int -KdAddKeyboard(KdKeyboardInfo * ki) -{ - KdKeyboardInfo **prev; - - if (!ki) - return !Success; - - ki->dixdev = AddInputDevice(serverClient, KdKeyboardProc, TRUE); - if (!ki->dixdev) { - ErrorF("Couldn't register keyboard device %s\n", - ki->name ? ki->name : "(unnamed)"); - return !Success; - } - -#ifdef DEBUG - ErrorF("added keyboard %s with dix id %d\n", ki->name, ki->dixdev->id); -#endif - - for (prev = &kdKeyboards; *prev; prev = &(*prev)->next); - *prev = ki; - - return Success; -} - -void -KdRemoveKeyboard(KdKeyboardInfo * ki) -{ - KdKeyboardInfo **prev; - - if (!ki) - return; - - for (prev = &kdKeyboards; *prev; prev = &(*prev)->next) { - if (*prev == ki) { - *prev = ki->next; - break; - } - } - - KdFreeKeyboard(ki); -} - -int -KdAddConfigPointer(char *pointer) -{ - struct KdConfigDevice **prev, *new; - - if (!pointer) - return Success; - - new = (struct KdConfigDevice *) calloc(sizeof(struct KdConfigDevice), 1); - if (!new) - return BadAlloc; - - new->line = strdup(pointer); - new->next = NULL; - - for (prev = &kdConfigPointers; *prev; prev = &(*prev)->next); - *prev = new; - - return Success; -} - -int -KdAddPointer(KdPointerInfo * pi) -{ - KdPointerInfo **prev; - - if (!pi) - return Success; - - pi->mouseState = start; - pi->eventHeld = FALSE; - - pi->dixdev = AddInputDevice(serverClient, KdPointerProc, TRUE); - if (!pi->dixdev) { - ErrorF("Couldn't add pointer device %s\n", - pi->name ? pi->name : "(unnamed)"); - return BadDevice; - } - - for (prev = &kdPointers; *prev; prev = &(*prev)->next); - *prev = pi; - - return Success; -} - -void -KdRemovePointer(KdPointerInfo * pi) -{ - KdPointerInfo **prev; - - if (!pi) - return; - - for (prev = &kdPointers; *prev; prev = &(*prev)->next) { - if (*prev == pi) { - *prev = pi->next; - break; - } - } - - KdFreePointer(pi); -} - -/* - * You can call your kdriver server with something like: - * $ ./hw/kdrive/yourserver/X :1 -mouse evdev,,device=/dev/input/event4 -keybd - * evdev,,device=/dev/input/event1,xkbmodel=abnt2,xkblayout=br - */ -static Bool -KdGetOptions(InputOption **options, char *string) -{ - InputOption *newopt = NULL; - char *key = NULL, *value = NULL; - int tam_key = 0; - - if (strchr(string, '=')) { - tam_key = (strchr(string, '=') - string); - key = strndup(string, tam_key); - if (!key) - goto out; - - value = strdup(strchr(string, '=') + 1); - if (!value) - goto out; - } - else { - key = strdup(string); - value = NULL; - } - - newopt = input_option_new(*options, key, value); - if (newopt) - *options = newopt; - - out: - free(key); - free(value); - - return (newopt != NULL); -} - -static void -KdParseKbdOptions(KdKeyboardInfo * ki) -{ - InputOption *option = NULL; - - nt_list_for_each_entry(option, ki->options, list.next) { - const char *key = input_option_get_key(option); - const char *value = input_option_get_value(option); - - if ( -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - strcasecmp(key, "xkb_rules") == 0 || -#endif - strcasecmp(key, "XkbRules") == 0) - ki->xkbRules = strdup(value); - else if ( -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - strcasecmp(key, "xkb_model") == 0 || -#endif - strcasecmp(key, "XkbModel") == 0) - ki->xkbModel = strdup(value); - else if ( -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - strcasecmp(key, "xkb_layout") == 0 || -#endif - strcasecmp(key, "XkbLayout") == 0) - ki->xkbLayout = strdup(value); - else if ( -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - strcasecmp(key, "xkb_variant") == 0 || -#endif - strcasecmp(key, "XkbVariant") == 0) - ki->xkbVariant = strdup(value); - else if ( -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - strcasecmp(key, "xkb_options") == 0 || -#endif - strcasecmp(key, "XkbOptions") == 0) - ki->xkbOptions = strdup(value); - else if (!strcasecmp(key, "device")) { - if (ki->path != NULL) - free(ki->path); - ki->path = strdup(value); - } -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - else if (!strcasecmp(key, "path")) { - if (ki->path != NULL) - free(ki->path); - ki->path = strdup(value); - } - else if (!strcasecmp(key, "name")) { - free(ki->name); - ki->name = strdup(value); - } -#endif - else if (!strcasecmp(key, "driver")) - ki->driver = KdFindKeyboardDriver(value); - else - ErrorF("Kbd option key (%s) of value (%s) not assigned!\n", - key, value); - } -} - -static KdKeyboardInfo * -KdParseKeyboard(const char *arg) -{ - char save[1024]; - char delim; - InputOption *options = NULL; - KdKeyboardInfo *ki = NULL; - - ki = KdNewKeyboard(); - if (!ki) - return NULL; - - ki->name = strdup("Unknown KDrive Keyboard"); - ki->path = NULL; - ki->driver = NULL; - ki->driverPrivate = NULL; - ki->next = NULL; - - if (!arg) { - ErrorF("keybd: no arg\n"); - KdFreeKeyboard(ki); - return NULL; - } - - if (strlen(arg) >= sizeof(save)) { - ErrorF("keybd: arg too long\n"); - KdFreeKeyboard(ki); - return NULL; - } - - arg = KdParseFindNext(arg, ",", save, &delim); - if (!save[0]) { - ErrorF("keybd: failed on save[0]\n"); - KdFreeKeyboard(ki); - return NULL; - } - - if (strcmp(save, "auto") == 0) - ki->driverPrivate = NULL; - else - ki->driverPrivate = strdup(save); - - if (delim != ',') { - return ki; - } - - arg = KdParseFindNext(arg, ",", save, &delim); - - while (delim == ',') { - arg = KdParseFindNext(arg, ",", save, &delim); - - if (!KdGetOptions(&options, save)) { - KdFreeKeyboard(ki); - return NULL; - } - } - - if (options) { - ki->options = options; - KdParseKbdOptions(ki); - } - - return ki; -} - -static void -KdParsePointerOptions(KdPointerInfo * pi) -{ - InputOption *option = NULL; - - nt_list_for_each_entry(option, pi->options, list.next) { - const char *key = input_option_get_key(option); - const char *value = input_option_get_value(option); - - if (!strcasecmp(key, "emulatemiddle")) - pi->emulateMiddleButton = TRUE; - else if (!strcasecmp(key, "noemulatemiddle")) - pi->emulateMiddleButton = FALSE; - else if (!strcasecmp(key, "transformcoord")) - pi->transformCoordinates = TRUE; - else if (!strcasecmp(key, "rawcoord")) - pi->transformCoordinates = FALSE; - else if (!strcasecmp(key, "device")) { - if (pi->path != NULL) - free(pi->path); - pi->path = strdup(value); - } -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - else if (!strcasecmp(key, "path")) { - if (pi->path != NULL) - free(pi->path); - pi->path = strdup(value); - } - else if (!strcasecmp(key, "name")) { - free(pi->name); - pi->name = strdup(value); - } -#endif - else if (!strcasecmp(key, "protocol")) - pi->protocol = strdup(value); - else if (!strcasecmp(key, "driver")) - pi->driver = KdFindPointerDriver(value); - else - ErrorF("Pointer option key (%s) of value (%s) not assigned!\n", - key, value); - } -} - -static KdPointerInfo * -KdParsePointer(const char *arg) -{ - char save[1024]; - char delim; - KdPointerInfo *pi = NULL; - InputOption *options = NULL; - int i = 0; - - pi = KdNewPointer(); - if (!pi) - return NULL; - pi->emulateMiddleButton = kdEmulateMiddleButton; - pi->transformCoordinates = !kdRawPointerCoordinates; - pi->protocol = NULL; - pi->nButtons = 5; /* XXX should not be hardcoded */ - pi->inputClass = KD_MOUSE; - - if (!arg) { - ErrorF("mouse: no arg\n"); - KdFreePointer(pi); - return NULL; - } - - if (strlen(arg) >= sizeof(save)) { - ErrorF("mouse: arg too long\n"); - KdFreePointer(pi); - return NULL; - } - arg = KdParseFindNext(arg, ",", save, &delim); - if (!save[0]) { - ErrorF("failed on save[0]\n"); - KdFreePointer(pi); - return NULL; - } - - if (strcmp(save, "auto") == 0) - pi->driverPrivate = NULL; - else - pi->driverPrivate = strdup(save); - - if (delim != ',') { - return pi; - } - - arg = KdParseFindNext(arg, ",", save, &delim); - - while (delim == ',') { - arg = KdParseFindNext(arg, ",", save, &delim); - if (save[0] == '{') { - char *s = save + 1; - - i = 0; - while (*s && *s != '}') { - if ('1' <= *s && *s <= '0' + pi->nButtons) - pi->map[i] = *s - '0'; - else - UseMsg(); - s++; - } - } - else { - if (!KdGetOptions(&options, save)) { - KdFreePointer(pi); - return NULL; - } - } - } - - if (options) { - pi->options = options; - KdParsePointerOptions(pi); - } - - return pi; -} - -void -KdInitInput(void) -{ - KdPointerInfo *pi; - KdKeyboardInfo *ki; - struct KdConfigDevice *dev; - - if (kdConfigPointers || kdConfigKeyboards) - InputThreadPreInit(); - - kdInputEnabled = TRUE; - - for (dev = kdConfigPointers; dev; dev = dev->next) { - pi = KdParsePointer(dev->line); - if (!pi) - ErrorF("Failed to parse pointer\n"); - if (KdAddPointer(pi) != Success) - ErrorF("Failed to add pointer!\n"); - } - for (dev = kdConfigKeyboards; dev; dev = dev->next) { - ki = KdParseKeyboard(dev->line); - if (!ki) - ErrorF("Failed to parse keyboard\n"); - if (KdAddKeyboard(ki) != Success) - ErrorF("Failed to add keyboard!\n"); - } - - mieqInit(); - -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - if (SeatId) /* Enable input hot-plugging */ - config_init(); -#endif -} - -void -KdCloseInput(void) -{ -#if defined(CONFIG_UDEV) || defined(CONFIG_HAL) - if (SeatId) /* Input hot-plugging is enabled */ - config_fini(); -#endif - - mieqFini(); -} - -/* - * Middle button emulation state machine - * - * Possible transitions: - * Button 1 press v1 - * Button 1 release ^1 - * Button 2 press v2 - * Button 2 release ^2 - * Button 3 press v3 - * Button 3 release ^3 - * Button other press vo - * Button other release ^o - * Mouse motion <> - * Keyboard event k - * timeout ... - * outside box <-> - * - * States: - * start - * button_1_pend - * button_1_down - * button_2_down - * button_3_pend - * button_3_down - * synthetic_2_down_13 - * synthetic_2_down_3 - * synthetic_2_down_1 - * - * Transition diagram - * - * start - * v1 -> (hold) (settimeout) button_1_pend - * ^1 -> (deliver) start - * v2 -> (deliver) button_2_down - * ^2 -> (deliever) start - * v3 -> (hold) (settimeout) button_3_pend - * ^3 -> (deliver) start - * vo -> (deliver) start - * ^o -> (deliver) start - * <> -> (deliver) start - * k -> (deliver) start - * - * button_1_pend (button 1 is down, timeout pending) - * ^1 -> (release) (deliver) start - * v2 -> (release) (deliver) button_1_down - * ^2 -> (release) (deliver) button_1_down - * v3 -> (cleartimeout) (generate v2) synthetic_2_down_13 - * ^3 -> (release) (deliver) button_1_down - * vo -> (release) (deliver) button_1_down - * ^o -> (release) (deliver) button_1_down - * <-> -> (release) (deliver) button_1_down - * <> -> (deliver) button_1_pend - * k -> (release) (deliver) button_1_down - * ... -> (release) button_1_down - * - * button_1_down (button 1 is down) - * ^1 -> (deliver) start - * v2 -> (deliver) button_1_down - * ^2 -> (deliver) button_1_down - * v3 -> (deliver) button_1_down - * ^3 -> (deliver) button_1_down - * vo -> (deliver) button_1_down - * ^o -> (deliver) button_1_down - * <> -> (deliver) button_1_down - * k -> (deliver) button_1_down - * - * button_2_down (button 2 is down) - * v1 -> (deliver) button_2_down - * ^1 -> (deliver) button_2_down - * ^2 -> (deliver) start - * v3 -> (deliver) button_2_down - * ^3 -> (deliver) button_2_down - * vo -> (deliver) button_2_down - * ^o -> (deliver) button_2_down - * <> -> (deliver) button_2_down - * k -> (deliver) button_2_down - * - * button_3_pend (button 3 is down, timeout pending) - * v1 -> (generate v2) synthetic_2_down - * ^1 -> (release) (deliver) button_3_down - * v2 -> (release) (deliver) button_3_down - * ^2 -> (release) (deliver) button_3_down - * ^3 -> (release) (deliver) start - * vo -> (release) (deliver) button_3_down - * ^o -> (release) (deliver) button_3_down - * <-> -> (release) (deliver) button_3_down - * <> -> (deliver) button_3_pend - * k -> (release) (deliver) button_3_down - * ... -> (release) button_3_down - * - * button_3_down (button 3 is down) - * v1 -> (deliver) button_3_down - * ^1 -> (deliver) button_3_down - * v2 -> (deliver) button_3_down - * ^2 -> (deliver) button_3_down - * ^3 -> (deliver) start - * vo -> (deliver) button_3_down - * ^o -> (deliver) button_3_down - * <> -> (deliver) button_3_down - * k -> (deliver) button_3_down - * - * synthetic_2_down_13 (button 1 and 3 are down) - * ^1 -> (generate ^2) synthetic_2_down_3 - * v2 -> synthetic_2_down_13 - * ^2 -> synthetic_2_down_13 - * ^3 -> (generate ^2) synthetic_2_down_1 - * vo -> (deliver) synthetic_2_down_13 - * ^o -> (deliver) synthetic_2_down_13 - * <> -> (deliver) synthetic_2_down_13 - * k -> (deliver) synthetic_2_down_13 - * - * synthetic_2_down_3 (button 3 is down) - * v1 -> (deliver) synthetic_2_down_3 - * ^1 -> (deliver) synthetic_2_down_3 - * v2 -> synthetic_2_down_3 - * ^2 -> synthetic_2_down_3 - * ^3 -> start - * vo -> (deliver) synthetic_2_down_3 - * ^o -> (deliver) synthetic_2_down_3 - * <> -> (deliver) synthetic_2_down_3 - * k -> (deliver) synthetic_2_down_3 - * - * synthetic_2_down_1 (button 1 is down) - * ^1 -> start - * v2 -> synthetic_2_down_1 - * ^2 -> synthetic_2_down_1 - * v3 -> (deliver) synthetic_2_down_1 - * ^3 -> (deliver) synthetic_2_down_1 - * vo -> (deliver) synthetic_2_down_1 - * ^o -> (deliver) synthetic_2_down_1 - * <> -> (deliver) synthetic_2_down_1 - * k -> (deliver) synthetic_2_down_1 - */ - -typedef enum _inputClass { - down_1, up_1, - down_2, up_2, - down_3, up_3, - down_o, up_o, - motion, outside_box, - keyboard, timeout, - num_input_class -} KdInputClass; - -typedef enum _inputAction { - noop, - hold, - setto, - deliver, - release, - clearto, - gen_down_2, - gen_up_2 -} KdInputAction; - -#define MAX_ACTIONS 2 - -typedef struct _inputTransition { - KdInputAction actions[MAX_ACTIONS]; - KdPointerState nextState; -} KdInputTransition; - -static const -KdInputTransition kdInputMachine[num_input_states][num_input_class] = { - /* start */ - { - {{hold, setto}, button_1_pend}, /* v1 */ - {{deliver, noop}, start}, /* ^1 */ - {{deliver, noop}, button_2_down}, /* v2 */ - {{deliver, noop}, start}, /* ^2 */ - {{hold, setto}, button_3_pend}, /* v3 */ - {{deliver, noop}, start}, /* ^3 */ - {{deliver, noop}, start}, /* vo */ - {{deliver, noop}, start}, /* ^o */ - {{deliver, noop}, start}, /* <> */ - {{deliver, noop}, start}, /* <-> */ - {{noop, noop}, start}, /* k */ - {{noop, noop}, start}, /* ... */ - }, - /* button_1_pend */ - { - {{noop, noop}, button_1_pend}, /* v1 */ - {{release, deliver}, start}, /* ^1 */ - {{release, deliver}, button_1_down}, /* v2 */ - {{release, deliver}, button_1_down}, /* ^2 */ - {{clearto, gen_down_2}, synth_2_down_13}, /* v3 */ - {{release, deliver}, button_1_down}, /* ^3 */ - {{release, deliver}, button_1_down}, /* vo */ - {{release, deliver}, button_1_down}, /* ^o */ - {{deliver, noop}, button_1_pend}, /* <> */ - {{release, deliver}, button_1_down}, /* <-> */ - {{noop, noop}, button_1_down}, /* k */ - {{release, noop}, button_1_down}, /* ... */ - }, - /* button_1_down */ - { - {{noop, noop}, button_1_down}, /* v1 */ - {{deliver, noop}, start}, /* ^1 */ - {{deliver, noop}, button_1_down}, /* v2 */ - {{deliver, noop}, button_1_down}, /* ^2 */ - {{deliver, noop}, button_1_down}, /* v3 */ - {{deliver, noop}, button_1_down}, /* ^3 */ - {{deliver, noop}, button_1_down}, /* vo */ - {{deliver, noop}, button_1_down}, /* ^o */ - {{deliver, noop}, button_1_down}, /* <> */ - {{deliver, noop}, button_1_down}, /* <-> */ - {{noop, noop}, button_1_down}, /* k */ - {{noop, noop}, button_1_down}, /* ... */ - }, - /* button_2_down */ - { - {{deliver, noop}, button_2_down}, /* v1 */ - {{deliver, noop}, button_2_down}, /* ^1 */ - {{noop, noop}, button_2_down}, /* v2 */ - {{deliver, noop}, start}, /* ^2 */ - {{deliver, noop}, button_2_down}, /* v3 */ - {{deliver, noop}, button_2_down}, /* ^3 */ - {{deliver, noop}, button_2_down}, /* vo */ - {{deliver, noop}, button_2_down}, /* ^o */ - {{deliver, noop}, button_2_down}, /* <> */ - {{deliver, noop}, button_2_down}, /* <-> */ - {{noop, noop}, button_2_down}, /* k */ - {{noop, noop}, button_2_down}, /* ... */ - }, - /* button_3_pend */ - { - {{clearto, gen_down_2}, synth_2_down_13}, /* v1 */ - {{release, deliver}, button_3_down}, /* ^1 */ - {{release, deliver}, button_3_down}, /* v2 */ - {{release, deliver}, button_3_down}, /* ^2 */ - {{release, deliver}, button_3_down}, /* v3 */ - {{release, deliver}, start}, /* ^3 */ - {{release, deliver}, button_3_down}, /* vo */ - {{release, deliver}, button_3_down}, /* ^o */ - {{deliver, noop}, button_3_pend}, /* <> */ - {{release, deliver}, button_3_down}, /* <-> */ - {{release, noop}, button_3_down}, /* k */ - {{release, noop}, button_3_down}, /* ... */ - }, - /* button_3_down */ - { - {{deliver, noop}, button_3_down}, /* v1 */ - {{deliver, noop}, button_3_down}, /* ^1 */ - {{deliver, noop}, button_3_down}, /* v2 */ - {{deliver, noop}, button_3_down}, /* ^2 */ - {{noop, noop}, button_3_down}, /* v3 */ - {{deliver, noop}, start}, /* ^3 */ - {{deliver, noop}, button_3_down}, /* vo */ - {{deliver, noop}, button_3_down}, /* ^o */ - {{deliver, noop}, button_3_down}, /* <> */ - {{deliver, noop}, button_3_down}, /* <-> */ - {{noop, noop}, button_3_down}, /* k */ - {{noop, noop}, button_3_down}, /* ... */ - }, - /* synthetic_2_down_13 */ - { - {{noop, noop}, synth_2_down_13}, /* v1 */ - {{gen_up_2, noop}, synth_2_down_3}, /* ^1 */ - {{noop, noop}, synth_2_down_13}, /* v2 */ - {{noop, noop}, synth_2_down_13}, /* ^2 */ - {{noop, noop}, synth_2_down_13}, /* v3 */ - {{gen_up_2, noop}, synth_2_down_1}, /* ^3 */ - {{deliver, noop}, synth_2_down_13}, /* vo */ - {{deliver, noop}, synth_2_down_13}, /* ^o */ - {{deliver, noop}, synth_2_down_13}, /* <> */ - {{deliver, noop}, synth_2_down_13}, /* <-> */ - {{noop, noop}, synth_2_down_13}, /* k */ - {{noop, noop}, synth_2_down_13}, /* ... */ - }, - /* synthetic_2_down_3 */ - { - {{deliver, noop}, synth_2_down_3}, /* v1 */ - {{deliver, noop}, synth_2_down_3}, /* ^1 */ - {{deliver, noop}, synth_2_down_3}, /* v2 */ - {{deliver, noop}, synth_2_down_3}, /* ^2 */ - {{noop, noop}, synth_2_down_3}, /* v3 */ - {{noop, noop}, start}, /* ^3 */ - {{deliver, noop}, synth_2_down_3}, /* vo */ - {{deliver, noop}, synth_2_down_3}, /* ^o */ - {{deliver, noop}, synth_2_down_3}, /* <> */ - {{deliver, noop}, synth_2_down_3}, /* <-> */ - {{noop, noop}, synth_2_down_3}, /* k */ - {{noop, noop}, synth_2_down_3}, /* ... */ - }, - /* synthetic_2_down_1 */ - { - {{noop, noop}, synth_2_down_1}, /* v1 */ - {{noop, noop}, start}, /* ^1 */ - {{deliver, noop}, synth_2_down_1}, /* v2 */ - {{deliver, noop}, synth_2_down_1}, /* ^2 */ - {{deliver, noop}, synth_2_down_1}, /* v3 */ - {{deliver, noop}, synth_2_down_1}, /* ^3 */ - {{deliver, noop}, synth_2_down_1}, /* vo */ - {{deliver, noop}, synth_2_down_1}, /* ^o */ - {{deliver, noop}, synth_2_down_1}, /* <> */ - {{deliver, noop}, synth_2_down_1}, /* <-> */ - {{noop, noop}, synth_2_down_1}, /* k */ - {{noop, noop}, synth_2_down_1}, /* ... */ - }, -}; - -#define EMULATION_WINDOW 10 -#define EMULATION_TIMEOUT 100 - -static int -KdInsideEmulationWindow(KdPointerInfo * pi, int x, int y, int z) -{ - pi->emulationDx = pi->heldEvent.x - x; - pi->emulationDy = pi->heldEvent.y - y; - - return (abs(pi->emulationDx) < EMULATION_WINDOW && - abs(pi->emulationDy) < EMULATION_WINDOW); -} - -static KdInputClass -KdClassifyInput(KdPointerInfo * pi, int type, int x, int y, int z, int b) -{ - switch (type) { - case ButtonPress: - switch (b) { - case 1: - return down_1; - case 2: - return down_2; - case 3: - return down_3; - default: - return down_o; - } - break; - case ButtonRelease: - switch (b) { - case 1: - return up_1; - case 2: - return up_2; - case 3: - return up_3; - default: - return up_o; - } - break; - case MotionNotify: - if (pi->eventHeld && !KdInsideEmulationWindow(pi, x, y, z)) - return outside_box; - else - return motion; - default: - return keyboard; - } - return keyboard; -} - -static void -_KdEnqueuePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z, - int b, int absrel, Bool force); -/* We return true if we're stealing the event. */ -static Bool -KdRunMouseMachine(KdPointerInfo * pi, KdInputClass c, int type, int x, int y, - int z, int b, int absrel) -{ - const KdInputTransition *t; - int a; - - c = KdClassifyInput(pi, type, x, y, z, b); - t = &kdInputMachine[pi->mouseState][c]; - for (a = 0; a < MAX_ACTIONS; a++) { - switch (t->actions[a]) { - case noop: - break; - case hold: - pi->eventHeld = TRUE; - pi->emulationDx = 0; - pi->emulationDy = 0; - pi->heldEvent.type = type; - pi->heldEvent.x = x; - pi->heldEvent.y = y; - pi->heldEvent.z = z; - pi->heldEvent.flags = b; - pi->heldEvent.absrel = absrel; - return TRUE; - break; - case setto: - pi->emulationTimeout = GetTimeInMillis() + EMULATION_TIMEOUT; - pi->timeoutPending = TRUE; - break; - case deliver: - _KdEnqueuePointerEvent(pi, pi->heldEvent.type, pi->heldEvent.x, - pi->heldEvent.y, pi->heldEvent.z, - pi->heldEvent.flags, pi->heldEvent.absrel, - TRUE); - break; - case release: - pi->eventHeld = FALSE; - pi->timeoutPending = FALSE; - _KdEnqueuePointerEvent(pi, pi->heldEvent.type, pi->heldEvent.x, - pi->heldEvent.y, pi->heldEvent.z, - pi->heldEvent.flags, pi->heldEvent.absrel, - TRUE); - return TRUE; - break; - case clearto: - pi->timeoutPending = FALSE; - break; - case gen_down_2: - _KdEnqueuePointerEvent(pi, ButtonPress, x, y, z, 2, absrel, TRUE); - pi->eventHeld = FALSE; - return TRUE; - break; - case gen_up_2: - _KdEnqueuePointerEvent(pi, ButtonRelease, x, y, z, 2, absrel, TRUE); - return TRUE; - break; - } - } - pi->mouseState = t->nextState; - return FALSE; -} - -static int -KdHandlePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z, int b, - int absrel) -{ - if (pi->emulateMiddleButton) - return KdRunMouseMachine(pi, KdClassifyInput(pi, type, x, y, z, b), - type, x, y, z, b, absrel); - return FALSE; -} - -static void -_KdEnqueuePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z, - int b, int absrel, Bool force) -{ - int valuators[3] = { x, y, z }; - ValuatorMask mask; - - /* TRUE from KdHandlePointerEvent, means 'we swallowed the event'. */ - if (!force && KdHandlePointerEvent(pi, type, x, y, z, b, absrel)) - return; - - valuator_mask_set_range(&mask, 0, 3, valuators); - - QueuePointerEvents(pi->dixdev, type, b, absrel, &mask); -} - -static void -KdReceiveTimeout(KdPointerInfo * pi) -{ - KdRunMouseMachine(pi, timeout, 0, 0, 0, 0, 0, 0); -} - -extern int nClients; - -static void -KdCheckLock(void) -{ - KeyClassPtr keyc = NULL; - Bool isSet = FALSE, shouldBeSet = FALSE; - KdKeyboardInfo *tmp = NULL; - - for (tmp = kdKeyboards; tmp; tmp = tmp->next) { - if (tmp->LockLed && tmp->dixdev && tmp->dixdev->key) { - keyc = tmp->dixdev->key; - isSet = (tmp->leds & (1 << (tmp->LockLed - 1))) != 0; - /* FIXME: Just use XKB indicators! */ - shouldBeSet = - ! !(XkbStateFieldFromRec(&keyc->xkbInfo->state) & LockMask); - if (isSet != shouldBeSet) - KdSetLed(tmp, tmp->LockLed, shouldBeSet); - } - } -} - -void -KdEnqueueKeyboardEvent(KdKeyboardInfo * ki, - unsigned char scan_code, unsigned char is_up) -{ - unsigned char key_code; - int type; - - if (!ki || !ki->dixdev || !ki->dixdev->kbdfeed || !ki->dixdev->key) - return; - - if (scan_code >= ki->minScanCode && scan_code <= ki->maxScanCode) { - key_code = scan_code + KD_MIN_KEYCODE - ki->minScanCode; - - /* - * Set up this event -- the type may be modified below - */ - if (is_up) - type = KeyRelease; - else - type = KeyPress; - - QueueKeyboardEvents(ki->dixdev, type, key_code); - } - else { - ErrorF("driver %s wanted to post scancode %d outside of [%d, %d]!\n", - ki->name, scan_code, ki->minScanCode, ki->maxScanCode); - } -} - -/* - * kdEnqueuePointerEvent - * - * This function converts hardware mouse event information into X event - * information. A mouse movement event is passed off to MI to generate - * a MotionNotify event, if appropriate. Button events are created and - * passed off to MI for enqueueing. - */ - -/* FIXME do something a little more clever to deal with multiple axes here */ -void -KdEnqueuePointerEvent(KdPointerInfo * pi, unsigned long flags, int rx, int ry, - int rz) -{ - unsigned char buttons; - int x, y, z; - int (*matrix)[3] = kdPointerMatrix.matrix; - unsigned long button; - int n; - int dixflags = 0; - - if (!pi) - return; - - /* we don't need to transform z, so we don't. */ - if (flags & KD_MOUSE_DELTA) { - if (pi->transformCoordinates) { - x = matrix[0][0] * rx + matrix[0][1] * ry; - y = matrix[1][0] * rx + matrix[1][1] * ry; - } - else { - x = rx; - y = ry; - } - } - else { - if (pi->transformCoordinates) { - x = matrix[0][0] * rx + matrix[0][1] * ry + matrix[0][2]; - y = matrix[1][0] * rx + matrix[1][1] * ry + matrix[1][2]; - } - else { - x = rx; - y = ry; - } - } - z = rz; - - if (flags & KD_MOUSE_DELTA) { - if (x || y || z) { - dixflags = POINTER_RELATIVE | POINTER_ACCELERATE; - _KdEnqueuePointerEvent(pi, MotionNotify, x, y, z, 0, dixflags, - FALSE); - } - } - else { - dixflags = POINTER_ABSOLUTE; - if (flags & KD_POINTER_DESKTOP) - dixflags |= POINTER_DESKTOP; - if (x != pi->dixdev->last.valuators[0] || - y != pi->dixdev->last.valuators[1]) - _KdEnqueuePointerEvent(pi, MotionNotify, x, y, z, 0, dixflags, - FALSE); - } - - buttons = flags; - - for (button = KD_BUTTON_1, n = 1; n <= pi->nButtons; button <<= 1, n++) { - if (((pi->buttonState & button) ^ (buttons & button)) && - !(buttons & button)) { - _KdEnqueuePointerEvent(pi, ButtonRelease, x, y, z, n, - dixflags, FALSE); - } - } - for (button = KD_BUTTON_1, n = 1; n <= pi->nButtons; button <<= 1, n++) { - if (((pi->buttonState & button) ^ (buttons & button)) && - (buttons & button)) { - _KdEnqueuePointerEvent(pi, ButtonPress, x, y, z, n, - dixflags, FALSE); - } - } - - pi->buttonState = buttons; -} - -void -KdBlockHandler(ScreenPtr pScreen, void *timeo) -{ - KdPointerInfo *pi; - int myTimeout = 0; - - for (pi = kdPointers; pi; pi = pi->next) { - if (pi->timeoutPending) { - int ms; - - ms = pi->emulationTimeout - GetTimeInMillis(); - if (ms < 1) - ms = 1; - if (ms < myTimeout || myTimeout == 0) - myTimeout = ms; - } - } - if (myTimeout > 0) - AdjustWaitForDelay(timeo, myTimeout); -} - -void -KdWakeupHandler(ScreenPtr pScreen, int result) -{ - KdPointerInfo *pi; - - for (pi = kdPointers; pi; pi = pi->next) { - if (pi->timeoutPending) { - if ((long) (GetTimeInMillis() - pi->emulationTimeout) >= 0) { - pi->timeoutPending = FALSE; - input_lock(); - KdReceiveTimeout(pi); - input_unlock(); - } - } - } -} - -#define KdScreenOrigin(pScreen) (&(KdGetScreenPriv(pScreen)->screen->origin)) - -static Bool -KdCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y) -{ - ScreenPtr pScreen = *ppScreen; - ScreenPtr pNewScreen; - int n; - int dx, dy; - int best_x, best_y; - int n_best_x, n_best_y; - CARD32 ms; - - if (kdDisableZaphod || screenInfo.numScreens <= 1) - return FALSE; - - if (0 <= *x && *x < pScreen->width && 0 <= *y && *y < pScreen->height) - return FALSE; - - ms = GetTimeInMillis(); - if (kdOffScreen && (int) (ms - kdOffScreenTime) < 1000) - return FALSE; - kdOffScreen = TRUE; - kdOffScreenTime = ms; - n_best_x = -1; - best_x = 32767; - n_best_y = -1; - best_y = 32767; - for (n = 0; n < screenInfo.numScreens; n++) { - pNewScreen = screenInfo.screens[n]; - if (pNewScreen == pScreen) - continue; - dx = KdScreenOrigin(pNewScreen)->x - KdScreenOrigin(pScreen)->x; - dy = KdScreenOrigin(pNewScreen)->y - KdScreenOrigin(pScreen)->y; - if (*x < 0) { - if (dx < 0 && -dx < best_x) { - best_x = -dx; - n_best_x = n; - } - } - else if (*x >= pScreen->width) { - if (dx > 0 && dx < best_x) { - best_x = dx; - n_best_x = n; - } - } - if (*y < 0) { - if (dy < 0 && -dy < best_y) { - best_y = -dy; - n_best_y = n; - } - } - else if (*y >= pScreen->height) { - if (dy > 0 && dy < best_y) { - best_y = dy; - n_best_y = n; - } - } - } - if (best_y < best_x) - n_best_x = n_best_y; - if (n_best_x == -1) - return FALSE; - pNewScreen = screenInfo.screens[n_best_x]; - - if (*x < 0) - *x += pNewScreen->width; - if (*y < 0) - *y += pNewScreen->height; - - if (*x >= pScreen->width) - *x -= pScreen->width; - if (*y >= pScreen->height) - *y -= pScreen->height; - - *ppScreen = pNewScreen; - return TRUE; -} - -static void -KdCrossScreen(ScreenPtr pScreen, Bool entering) -{ -} - -static void -KdWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) -{ - input_lock(); - miPointerWarpCursor(pDev, pScreen, x, y); - input_unlock(); -} - -miPointerScreenFuncRec kdPointerScreenFuncs = { - KdCursorOffScreen, - KdCrossScreen, - KdWarpCursor -}; - -void -ProcessInputEvents(void) -{ - mieqProcessInputEvents(); - KdCheckLock(); -} - -/* At the moment, absolute/relative is up to the client. */ -int -SetDeviceMode(register ClientPtr client, DeviceIntPtr pDev, int mode) -{ - return BadMatch; -} - -int -SetDeviceValuators(register ClientPtr client, DeviceIntPtr pDev, - int *valuators, int first_valuator, int num_valuators) -{ - return BadMatch; -} - -int -ChangeDeviceControl(register ClientPtr client, DeviceIntPtr pDev, - xDeviceCtl * control) -{ - switch (control->control) { - case DEVICE_RESOLUTION: - /* FIXME do something more intelligent here */ - return BadMatch; - - case DEVICE_ABS_CALIB: - case DEVICE_ABS_AREA: - case DEVICE_CORE: - return BadMatch; - case DEVICE_ENABLE: - return Success; - - default: - return BadMatch; - } - - /* NOTREACHED */ - return BadImplementation; -} - -int -NewInputDeviceRequest(InputOption *options, InputAttributes * attrs, - DeviceIntPtr *pdev) -{ - InputOption *option = NULL, *optionsdup = NULL; - KdPointerInfo *pi = NULL; - KdKeyboardInfo *ki = NULL; - - nt_list_for_each_entry(option, options, list.next) { - const char *key = input_option_get_key(option); - const char *value = input_option_get_value(option); - optionsdup = input_option_new(optionsdup, key, value); - - if (strcmp(key, "type") == 0) { - if (strcmp(value, "pointer") == 0) { - pi = KdNewPointer(); - if (!pi) { - input_option_free_list(&optionsdup); - return BadAlloc; - } - } - else if (strcmp(value, "keyboard") == 0) { - ki = KdNewKeyboard(); - if (!ki) { - input_option_free_list(&optionsdup); - return BadAlloc; - } - } - else { - ErrorF("unrecognised device type!\n"); - return BadValue; - } - } -#ifdef CONFIG_HAL - else if (strcmp(key, "_source") == 0 && - strcmp(value, "server/hal") == 0) { - if (SeatId) { - /* Input hot-plugging is enabled */ - if (attrs->flags & ATTR_POINTER) { - pi = KdNewPointer(); - if (!pi) { - input_option_free_list(&optionsdup); - return BadAlloc; - } - } - else if (attrs->flags & ATTR_KEYBOARD) { - ki = KdNewKeyboard(); - if (!ki) { - input_option_free_list(&optionsdup); - return BadAlloc; - } - } - } - else { - ErrorF("Ignoring device from HAL.\n"); - input_option_free_list(&optionsdup); - return BadValue; - } - } -#endif -#ifdef CONFIG_UDEV - else if (strcmp(key, "_source") == 0 && - strcmp(value, "server/udev") == 0) { - if (SeatId) { - /* Input hot-plugging is enabled */ - if (attrs->flags & ATTR_POINTER) { - pi = KdNewPointer(); - if (!pi) { - input_option_free_list(&optionsdup); - return BadAlloc; - } - } - else if (attrs->flags & ATTR_KEYBOARD) { - ki = KdNewKeyboard(); - if (!ki) { - input_option_free_list(&optionsdup); - return BadAlloc; - } - } - } - else { - ErrorF("Ignoring device from udev.\n"); - input_option_free_list(&optionsdup); - return BadValue; - } - } -#endif - } - - if (pi) { - pi->options = optionsdup; - KdParsePointerOptions(pi); - - if (!pi->driver) { - ErrorF("couldn't find driver for pointer device \"%s\" (%s)\n", - pi->name ? pi->name : "(unnamed)", pi->path); - KdFreePointer(pi); - return BadValue; - } - - if (KdAddPointer(pi) != Success || - ActivateDevice(pi->dixdev, TRUE) != Success || - EnableDevice(pi->dixdev, TRUE) != TRUE) { - ErrorF("couldn't add or enable pointer \"%s\" (%s)\n", - pi->name ? pi->name : "(unnamed)", pi->path); - KdFreePointer(pi); - return BadImplementation; - } - - *pdev = pi->dixdev; - } - else if (ki) { - ki->options = optionsdup; - KdParseKbdOptions(ki); - - if (!ki->driver) { - ErrorF("couldn't find driver for keyboard device \"%s\" (%s)\n", - ki->name ? ki->name : "(unnamed)", ki->path); - KdFreeKeyboard(ki); - return BadValue; - } - - if (KdAddKeyboard(ki) != Success || - ActivateDevice(ki->dixdev, TRUE) != Success || - EnableDevice(ki->dixdev, TRUE) != TRUE) { - ErrorF("couldn't add or enable keyboard \"%s\" (%s)\n", - ki->name ? ki->name : "(unnamed)", ki->path); - KdFreeKeyboard(ki); - return BadImplementation; - } - - *pdev = ki->dixdev; - } - else { - ErrorF("unrecognised device identifier: %s\n", - input_option_get_value(input_option_find(optionsdup, - "device"))); - input_option_free_list(&optionsdup); - return BadValue; - } - - return Success; -} - -void -DeleteInputDeviceRequest(DeviceIntPtr pDev) -{ - RemoveDevice(pDev, TRUE); -} - -void -RemoveInputDeviceTraces(const char *config_info) -{ -} diff --git a/hw/kdrive/src/kshadow.c b/hw/kdrive/src/kshadow.c deleted file mode 100644 index 0cc8a1309..000000000 --- a/hw/kdrive/src/kshadow.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright © 1999 Keith Packard - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of Keith Packard not be used in - * advertising or publicity pertaining to distribution of the software without - * specific, written prior permission. Keith Packard makes no - * representations about the suitability of this software for any purpose. It - * is provided "as is" without express or implied warranty. - * - * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO - * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, - * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "kdrive.h" - -Bool -KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate) -{ - int paddedWidth; - void *buf; - int width = rotate ? screen->height : screen->width; - int height = rotate ? screen->width : screen->height; - int bpp = screen->fb.bitsPerPixel; - - /* use fb computation for width */ - paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits); - buf = xallocarray(paddedWidth, height); - if (!buf) - return FALSE; - if (screen->fb.shadow) - free(screen->fb.frameBuffer); - screen->fb.shadow = TRUE; - screen->fb.frameBuffer = buf; - screen->fb.byteStride = paddedWidth; - screen->fb.pixelStride = paddedWidth * 8 / bpp; - return TRUE; -} - -void -KdShadowFbFree(KdScreenInfo * screen) -{ - if (screen->fb.shadow) { - free(screen->fb.frameBuffer); - screen->fb.frameBuffer = 0; - screen->fb.shadow = FALSE; - } -} - -Bool -KdShadowSet(ScreenPtr pScreen, int randr, ShadowUpdateProc update, - ShadowWindowProc window) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - - shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen)); - if (screen->fb.shadow) { - return shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen), - update, window, randr, 0); - } - return TRUE; -} - -void -KdShadowUnset(ScreenPtr pScreen) -{ - shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen)); -} diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c deleted file mode 100644 index cb04f48cc..000000000 --- a/hw/kdrive/src/kxv.c +++ /dev/null @@ -1,1373 +0,0 @@ -/* - - XFree86 Xv DDX written by Mark Vojkovich (markv@valinux.com) - Adapted for KDrive by Pontus Lidman - - Copyright (C) 2000, 2001 - Nokia Home Communications - Copyright (C) 1998, 1999 - The XFree86 Project Inc. - -All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, and/or sell copies of the Software, and to permit persons -to whom the Software is furnished to do so, provided that the above -copyright notice(s) and this permission notice appear in all copies of -the Software and that both the above copyright notice(s) and this -permission notice appear in supporting documentation. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY -SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF -CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -Except as contained in this notice, the name of a copyright holder -shall not be used in advertising or otherwise to promote the sale, use -or other dealings in this Software without prior written authorization -of the copyright holder. - -*/ - -#ifdef HAVE_DIX_CONFIG_H -#include -#endif -#include "kdrive.h" - -#include "scrnintstr.h" -#include "regionstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" -#include "validate.h" -#include "resource.h" -#include "gcstruct.h" -#include "dixstruct.h" - -#include -#include - -#include "kxv.h" -#include "fourcc.h" - -/* XvAdaptorRec fields */ - -static int KdXVPutVideo(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int KdXVPutStill(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int KdXVGetVideo(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int KdXVGetStill(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16); -static int KdXVStopVideo(XvPortPtr, DrawablePtr); -static int KdXVSetPortAttribute(XvPortPtr, Atom, INT32); -static int KdXVGetPortAttribute(XvPortPtr, Atom, INT32 *); -static int KdXVQueryBestSize(XvPortPtr, CARD8, - CARD16, CARD16, CARD16, CARD16, - unsigned int *, unsigned int *); -static int KdXVPutImage(DrawablePtr, XvPortPtr, GCPtr, - INT16, INT16, CARD16, CARD16, - INT16, INT16, CARD16, CARD16, - XvImagePtr, unsigned char *, Bool, CARD16, CARD16); -static int KdXVQueryImageAttributes(XvPortPtr, XvImagePtr, - CARD16 *, CARD16 *, int *, int *); - -/* ScreenRec fields */ - -static Bool KdXVDestroyWindow(WindowPtr pWin); -static void KdXVWindowExposures(WindowPtr pWin, RegionPtr r1); -static void KdXVClipNotify(WindowPtr pWin, int dx, int dy); -static Bool KdXVCloseScreen(ScreenPtr); - -/* misc */ -static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr, int); - -static DevPrivateKeyRec KdXVWindowKeyRec; - -#define KdXVWindowKey (&KdXVWindowKeyRec) -static DevPrivateKey KdXvScreenKey; -static DevPrivateKeyRec KdXVScreenPrivateKey; -static unsigned long KdXVGeneration = 0; -static unsigned long PortResource = 0; - -#define GET_XV_SCREEN(pScreen) ((XvScreenPtr) \ - dixLookupPrivate(&(pScreen)->devPrivates, KdXvScreenKey)) - -#define GET_KDXV_SCREEN(pScreen) \ - ((KdXVScreenPtr)(dixGetPrivate(&pScreen->devPrivates, &KdXVScreenPrivateKey))) - -#define GET_KDXV_WINDOW(pWin) ((KdXVWindowPtr) \ - dixLookupPrivate(&(pWin)->devPrivates, KdXVWindowKey)) - -Bool -KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num) -{ - KdXVScreenPtr ScreenPriv; - -/* fprintf(stderr,"KdXVScreenInit initializing %d adaptors\n",num); */ - - if (KdXVGeneration != serverGeneration) - KdXVGeneration = serverGeneration; - - if (noXvExtension) - return FALSE; - - if (!dixRegisterPrivateKey(&KdXVWindowKeyRec, PRIVATE_WINDOW, 0)) - return FALSE; - if (!dixRegisterPrivateKey(&KdXVScreenPrivateKey, PRIVATE_SCREEN, 0)) - return FALSE; - - if (Success != XvScreenInit(pScreen)) - return FALSE; - - KdXvScreenKey = XvGetScreenKey(); - PortResource = XvGetRTPort(); - - ScreenPriv = malloc(sizeof(KdXVScreenRec)); - dixSetPrivate(&pScreen->devPrivates, &KdXVScreenPrivateKey, ScreenPriv); - - if (!ScreenPriv) - return FALSE; - - ScreenPriv->DestroyWindow = pScreen->DestroyWindow; - ScreenPriv->WindowExposures = pScreen->WindowExposures; - ScreenPriv->ClipNotify = pScreen->ClipNotify; - ScreenPriv->CloseScreen = pScreen->CloseScreen; - -/* fprintf(stderr,"XV: Wrapping screen funcs\n"); */ - - pScreen->DestroyWindow = KdXVDestroyWindow; - pScreen->WindowExposures = KdXVWindowExposures; - pScreen->ClipNotify = KdXVClipNotify; - pScreen->CloseScreen = KdXVCloseScreen; - - if (!KdXVInitAdaptors(pScreen, adaptors, num)) - return FALSE; - - return TRUE; -} - -static void -KdXVFreeAdaptor(XvAdaptorPtr pAdaptor) -{ - int i; - - if (pAdaptor->pPorts) { - XvPortPtr pPort = pAdaptor->pPorts; - XvPortRecPrivatePtr pPriv; - - for (i = 0; i < pAdaptor->nPorts; i++, pPort++) { - pPriv = (XvPortRecPrivatePtr) pPort->devPriv.ptr; - if (pPriv) { - if (pPriv->clientClip) - RegionDestroy(pPriv->clientClip); - if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); - free(pPriv); - } - } - } - - XvFreeAdaptor(pAdaptor); -} - -static Bool -KdXVInitAdaptors(ScreenPtr pScreen, KdVideoAdaptorPtr infoPtr, int number) -{ - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - KdVideoAdaptorPtr adaptorPtr; - XvAdaptorPtr pAdaptor, pa; - XvAdaptorRecPrivatePtr adaptorPriv; - int na, numAdaptor; - XvPortRecPrivatePtr portPriv; - XvPortPtr pPort, pp; - int numPort; - KdVideoFormatPtr formatPtr; - XvFormatPtr pFormat, pf; - int numFormat, totFormat; - KdVideoEncodingPtr encodingPtr; - XvEncodingPtr pEncode, pe; - int numVisuals; - VisualPtr pVisual; - int i; - - pxvs->nAdaptors = 0; - pxvs->pAdaptors = NULL; - - if (!(pAdaptor = calloc(number, sizeof(XvAdaptorRec)))) - return FALSE; - - for (pa = pAdaptor, na = 0, numAdaptor = 0; na < number; na++, adaptorPtr++) { - adaptorPtr = &infoPtr[na]; - - if (!adaptorPtr->StopVideo || !adaptorPtr->SetPortAttribute || - !adaptorPtr->GetPortAttribute || !adaptorPtr->QueryBestSize) - continue; - - /* client libs expect at least one encoding */ - if (!adaptorPtr->nEncodings || !adaptorPtr->pEncodings) - continue; - - pa->type = adaptorPtr->type; - - if (!adaptorPtr->PutVideo && !adaptorPtr->GetVideo) - pa->type &= ~XvVideoMask; - - if (!adaptorPtr->PutStill && !adaptorPtr->GetStill) - pa->type &= ~XvStillMask; - - if (!adaptorPtr->PutImage || !adaptorPtr->QueryImageAttributes) - pa->type &= ~XvImageMask; - - if (!adaptorPtr->PutVideo && !adaptorPtr->PutImage && - !adaptorPtr->PutStill) - pa->type &= ~XvInputMask; - - if (!adaptorPtr->GetVideo && !adaptorPtr->GetStill) - pa->type &= ~XvOutputMask; - - if (!(adaptorPtr->type & (XvPixmapMask | XvWindowMask))) - continue; - if (!(adaptorPtr->type & (XvImageMask | XvVideoMask | XvStillMask))) - continue; - - pa->pScreen = pScreen; - pa->ddPutVideo = KdXVPutVideo; - pa->ddPutStill = KdXVPutStill; - pa->ddGetVideo = KdXVGetVideo; - pa->ddGetStill = KdXVGetStill; - pa->ddStopVideo = KdXVStopVideo; - pa->ddPutImage = KdXVPutImage; - pa->ddSetPortAttribute = KdXVSetPortAttribute; - pa->ddGetPortAttribute = KdXVGetPortAttribute; - pa->ddQueryBestSize = KdXVQueryBestSize; - pa->ddQueryImageAttributes = KdXVQueryImageAttributes; - pa->name = strdup(adaptorPtr->name); - - if (adaptorPtr->nEncodings && - (pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) { - - for (pe = pEncode, encodingPtr = adaptorPtr->pEncodings, i = 0; - i < adaptorPtr->nEncodings; pe++, i++, encodingPtr++) { - pe->id = encodingPtr->id; - pe->pScreen = pScreen; - pe->name = strdup(encodingPtr->name); - pe->width = encodingPtr->width; - pe->height = encodingPtr->height; - pe->rate.numerator = encodingPtr->rate.numerator; - pe->rate.denominator = encodingPtr->rate.denominator; - } - pa->nEncodings = adaptorPtr->nEncodings; - pa->pEncodings = pEncode; - } - - if (adaptorPtr->nImages && - (pa->pImages = calloc(adaptorPtr->nImages, sizeof(XvImageRec)))) { - memcpy(pa->pImages, adaptorPtr->pImages, - adaptorPtr->nImages * sizeof(XvImageRec)); - pa->nImages = adaptorPtr->nImages; - } - - if (adaptorPtr->nAttributes && - (pa->pAttributes = calloc(adaptorPtr->nAttributes, - sizeof(XvAttributeRec)))) { - memcpy(pa->pAttributes, adaptorPtr->pAttributes, - adaptorPtr->nAttributes * sizeof(XvAttributeRec)); - - for (i = 0; i < adaptorPtr->nAttributes; i++) { - pa->pAttributes[i].name = - strdup(adaptorPtr->pAttributes[i].name); - } - - pa->nAttributes = adaptorPtr->nAttributes; - } - - totFormat = adaptorPtr->nFormats; - - if (!(pFormat = calloc(totFormat, sizeof(XvFormatRec)))) { - KdXVFreeAdaptor(pa); - continue; - } - for (pf = pFormat, i = 0, numFormat = 0, formatPtr = - adaptorPtr->pFormats; i < adaptorPtr->nFormats; i++, formatPtr++) { - numVisuals = pScreen->numVisuals; - pVisual = pScreen->visuals; - - while (numVisuals--) { - if ((pVisual->class == formatPtr->class) && - (pVisual->nplanes == formatPtr->depth)) { - - if (numFormat >= totFormat) { - void *moreSpace; - - totFormat *= 2; - moreSpace = reallocarray(pFormat, totFormat, - sizeof(XvFormatRec)); - if (!moreSpace) - break; - pFormat = moreSpace; - pf = pFormat + numFormat; - } - - pf->visual = pVisual->vid; - pf->depth = formatPtr->depth; - - pf++; - numFormat++; - } - pVisual++; - } - } - pa->nFormats = numFormat; - pa->pFormats = pFormat; - if (!numFormat) { - KdXVFreeAdaptor(pa); - continue; - } - - if (!(adaptorPriv = calloc(1, sizeof(XvAdaptorRecPrivate)))) { - KdXVFreeAdaptor(pa); - continue; - } - - adaptorPriv->flags = adaptorPtr->flags; - adaptorPriv->PutVideo = adaptorPtr->PutVideo; - adaptorPriv->PutStill = adaptorPtr->PutStill; - adaptorPriv->GetVideo = adaptorPtr->GetVideo; - adaptorPriv->GetStill = adaptorPtr->GetStill; - adaptorPriv->StopVideo = adaptorPtr->StopVideo; - adaptorPriv->SetPortAttribute = adaptorPtr->SetPortAttribute; - adaptorPriv->GetPortAttribute = adaptorPtr->GetPortAttribute; - adaptorPriv->QueryBestSize = adaptorPtr->QueryBestSize; - adaptorPriv->QueryImageAttributes = adaptorPtr->QueryImageAttributes; - adaptorPriv->PutImage = adaptorPtr->PutImage; - adaptorPriv->ReputImage = adaptorPtr->ReputImage; - - pa->devPriv.ptr = (void *) adaptorPriv; - - if (!(pPort = calloc(adaptorPtr->nPorts, sizeof(XvPortRec)))) { - KdXVFreeAdaptor(pa); - continue; - } - for (pp = pPort, i = 0, numPort = 0; i < adaptorPtr->nPorts; i++) { - - if (!(pp->id = FakeClientID(0))) - continue; - - if (!(portPriv = calloc(1, sizeof(XvPortRecPrivate)))) - continue; - - if (!AddResource(pp->id, PortResource, pp)) { - free(portPriv); - continue; - } - - pp->pAdaptor = pa; - pp->pNotify = (XvPortNotifyPtr) NULL; - pp->pDraw = (DrawablePtr) NULL; - pp->client = (ClientPtr) NULL; - pp->grab.client = (ClientPtr) NULL; - pp->time = currentTime; - pp->devPriv.ptr = portPriv; - - portPriv->screen = screen; - portPriv->AdaptorRec = adaptorPriv; - portPriv->DevPriv.ptr = adaptorPtr->pPortPrivates[i].ptr; - - pp++; - numPort++; - } - pa->nPorts = numPort; - pa->pPorts = pPort; - if (!numPort) { - KdXVFreeAdaptor(pa); - continue; - } - - pa->base_id = pPort->id; - - pa++; - numAdaptor++; - } - - if (numAdaptor) { - pxvs->nAdaptors = numAdaptor; - pxvs->pAdaptors = pAdaptor; - } - else { - free(pAdaptor); - return FALSE; - } - - return TRUE; -} - -/* Video should be clipped to the intersection of the window cliplist - and the client cliplist specified in the GC for which the video was - initialized. When we need to reclip a window, the GC that started - the video may not even be around anymore. That's why we save the - client clip from the GC when the video is initialized. We then - use KdXVUpdateCompositeClip to calculate the new composite clip - when we need it. This is different from what DEC did. They saved - the GC and used its clip list when they needed to reclip the window, - even if the client clip was different from the one the video was - initialized with. If the original GC was destroyed, they had to stop - the video. I like the new method better (MArk). - - This function only works for windows. Will need to rewrite when - (if) we support pixmap rendering. -*/ - -static void -KdXVUpdateCompositeClip(XvPortRecPrivatePtr portPriv) -{ - RegionPtr pregWin, pCompositeClip; - WindowPtr pWin; - Bool freeCompClip = FALSE; - - if (portPriv->pCompositeClip) - return; - - pWin = (WindowPtr) portPriv->pDraw; - - /* get window clip list */ - if (portPriv->subWindowMode == IncludeInferiors) { - pregWin = NotClippedByChildren(pWin); - freeCompClip = TRUE; - } - else - pregWin = &pWin->clipList; - - if (!portPriv->clientClip) { - portPriv->pCompositeClip = pregWin; - portPriv->FreeCompositeClip = freeCompClip; - return; - } - - pCompositeClip = RegionCreate(NullBox, 1); - RegionCopy(pCompositeClip, portPriv->clientClip); - RegionTranslate(pCompositeClip, - portPriv->pDraw->x + portPriv->clipOrg.x, - portPriv->pDraw->y + portPriv->clipOrg.y); - RegionIntersect(pCompositeClip, pregWin, pCompositeClip); - - portPriv->pCompositeClip = pCompositeClip; - portPriv->FreeCompositeClip = TRUE; - - if (freeCompClip) { - RegionDestroy(pregWin); - } -} - -/* Save the current clientClip and update the CompositeClip whenever - we have a fresh GC */ - -static void -KdXVCopyClip(XvPortRecPrivatePtr portPriv, GCPtr pGC) -{ - /* copy the new clip if it exists */ - if (pGC->clientClip) { - if (!portPriv->clientClip) - portPriv->clientClip = RegionCreate(NullBox, 1); - /* Note: this is in window coordinates */ - RegionCopy(portPriv->clientClip, pGC->clientClip); - } - else if (portPriv->clientClip) { /* free the old clientClip */ - RegionDestroy(portPriv->clientClip); - portPriv->clientClip = NULL; - } - - /* get rid of the old clip list */ - if (portPriv->pCompositeClip && portPriv->FreeCompositeClip) { - RegionDestroy(portPriv->pCompositeClip); - } - - portPriv->clipOrg = pGC->clipOrg; - portPriv->pCompositeClip = pGC->pCompositeClip; - portPriv->FreeCompositeClip = FALSE; - portPriv->subWindowMode = pGC->subWindowMode; -} - -static int -KdXVRegetVideo(XvPortRecPrivatePtr portPriv) -{ - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - KdXVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionInit(&ClipRegion, NullBox, 1); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* that's all if it's totally obscured */ - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->GetVideo) (portPriv->screen, portPriv->pDraw, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, - portPriv->DevPriv.ptr); - - if (ret == Success) - portPriv->isOn = XV_ON; - - CLIP_VIDEO_BAILOUT: - - if ((clippedAway || (ret != Success)) && portPriv->isOn == XV_ON) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -KdXVReputVideo(XvPortRecPrivatePtr portPriv) -{ - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - ScreenPtr pScreen = portPriv->pDraw->pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - int ret = Success; - Bool clippedAway = FALSE; - - KdXVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionInit(&ClipRegion, NullBox, 1); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* clip and translate to the viewport */ - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = 0; - VPBox.y1 = 0; - VPBox.x2 = screen->width; - VPBox.y2 = screen->height; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* that's all if it's totally obscured */ - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->screen, portPriv->pDraw, - portPriv->vid_x, portPriv->vid_y, - WinBox.x1, WinBox.y1, - portPriv->vid_w, portPriv->vid_h, - portPriv->drw_w, portPriv->drw_h, - &ClipRegion, - portPriv->DevPriv.ptr); - - if (ret == Success) - portPriv->isOn = XV_ON; - - CLIP_VIDEO_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -KdXVReputImage(XvPortRecPrivatePtr portPriv) -{ - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - ScreenPtr pScreen = portPriv->pDraw->pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - int ret = Success; - Bool clippedAway = FALSE; - - KdXVUpdateCompositeClip(portPriv); - - /* translate the video region to the screen */ - WinBox.x1 = portPriv->pDraw->x + portPriv->drw_x; - WinBox.y1 = portPriv->pDraw->y + portPriv->drw_y; - WinBox.x2 = WinBox.x1 + portPriv->drw_w; - WinBox.y2 = WinBox.y1 + portPriv->drw_h; - - /* clip to the window composite clip */ - RegionInit(&WinRegion, &WinBox, 1); - RegionInit(&ClipRegion, NullBox, 1); - RegionIntersect(&ClipRegion, &WinRegion, portPriv->pCompositeClip); - - /* clip and translate to the viewport */ - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = 0; - VPBox.y1 = 0; - VPBox.x2 = screen->width; - VPBox.y2 = screen->height; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - /* that's all if it's totally obscured */ - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto CLIP_VIDEO_BAILOUT; - } - - ret = - (*portPriv->AdaptorRec->ReputImage) (portPriv->screen, portPriv->pDraw, - WinBox.x1, WinBox.y1, &ClipRegion, - portPriv->DevPriv.ptr); - - portPriv->isOn = (ret == Success) ? XV_ON : XV_OFF; - - CLIP_VIDEO_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - /* This clip was copied and only good for one shot */ - if (!portPriv->FreeCompositeClip) - portPriv->pCompositeClip = NULL; - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -KdXVEnlistPortInWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv) -{ - KdXVWindowPtr winPriv, PrivRoot; - - winPriv = PrivRoot = GET_KDXV_WINDOW(pWin); - - /* Enlist our port in the window private */ - while (winPriv) { - if (winPriv->PortRec == portPriv) /* we're already listed */ - break; - winPriv = winPriv->next; - } - - if (!winPriv) { - winPriv = malloc(sizeof(KdXVWindowRec)); - if (!winPriv) - return BadAlloc; - winPriv->PortRec = portPriv; - winPriv->next = PrivRoot; - dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv); - } - return Success; -} - -static void -KdXVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv) -{ - KdXVWindowPtr winPriv, prevPriv = NULL; - - winPriv = GET_KDXV_WINDOW(pWin); - - while (winPriv) { - if (winPriv->PortRec == portPriv) { - if (prevPriv) - prevPriv->next = winPriv->next; - else - dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, winPriv->next); - free(winPriv); - break; - } - prevPriv = winPriv; - winPriv = winPriv->next; - } - portPriv->pDraw = NULL; -} - -/**** ScreenRec fields ****/ - -static Bool -KdXVDestroyWindow(WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen); - KdXVWindowPtr tmp, WinPriv = GET_KDXV_WINDOW(pWin); - int ret; - - while (WinPriv) { - XvPortRecPrivatePtr pPriv = WinPriv->PortRec; - - if (pPriv->isOn > XV_OFF) { - (*pPriv->AdaptorRec->StopVideo) (pPriv->screen, pPriv->DevPriv.ptr, - TRUE); - pPriv->isOn = XV_OFF; - } - - pPriv->pDraw = NULL; - tmp = WinPriv; - WinPriv = WinPriv->next; - free(tmp); - } - - dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, NULL); - - pScreen->DestroyWindow = ScreenPriv->DestroyWindow; - ret = (*pScreen->DestroyWindow) (pWin); - pScreen->DestroyWindow = KdXVDestroyWindow; - - return ret; -} - -static void -KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen); - KdXVWindowPtr WinPriv = GET_KDXV_WINDOW(pWin); - KdXVWindowPtr pPrev; - XvPortRecPrivatePtr pPriv; - Bool AreasExposed; - - AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1)); - - pScreen->WindowExposures = ScreenPriv->WindowExposures; - (*pScreen->WindowExposures) (pWin, reg1); - pScreen->WindowExposures = KdXVWindowExposures; - - /* filter out XClearWindow/Area */ - if (!pWin->valdata) - return; - - pPrev = NULL; - - while (WinPriv) { - pPriv = WinPriv->PortRec; - - /* Reput anyone with a reput function */ - - switch (pPriv->type) { - case XvInputMask: - KdXVReputVideo(pPriv); - break; - case XvOutputMask: - KdXVRegetVideo(pPriv); - break; - default: /* overlaid still/image */ - if (pPriv->AdaptorRec->ReputImage) - KdXVReputImage(pPriv); - else if (AreasExposed) { - KdXVWindowPtr tmp; - - if (pPriv->isOn == XV_ON) { - (*pPriv->AdaptorRec->StopVideo) (pPriv->screen, - pPriv->DevPriv.ptr, FALSE); - pPriv->isOn = XV_PENDING; - } - pPriv->pDraw = NULL; - - if (!pPrev) - dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, - WinPriv->next); - else - pPrev->next = WinPriv->next; - tmp = WinPriv; - WinPriv = WinPriv->next; - free(tmp); - continue; - } - break; - } - pPrev = WinPriv; - WinPriv = WinPriv->next; - } -} - -static void -KdXVClipNotify(WindowPtr pWin, int dx, int dy) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen); - KdXVWindowPtr WinPriv = GET_KDXV_WINDOW(pWin); - KdXVWindowPtr tmp, pPrev = NULL; - XvPortRecPrivatePtr pPriv; - Bool visible = (pWin->visibility == VisibilityUnobscured) || - (pWin->visibility == VisibilityPartiallyObscured); - - while (WinPriv) { - pPriv = WinPriv->PortRec; - - if (pPriv->pCompositeClip && pPriv->FreeCompositeClip) - RegionDestroy(pPriv->pCompositeClip); - - pPriv->pCompositeClip = NULL; - - /* Stop everything except images, but stop them too if the - window isn't visible. But we only remove the images. */ - - if (pPriv->type || !visible) { - if (pPriv->isOn == XV_ON) { - (*pPriv->AdaptorRec->StopVideo) (pPriv->screen, - pPriv->DevPriv.ptr, FALSE); - pPriv->isOn = XV_PENDING; - } - - if (!pPriv->type) { /* overlaid still/image */ - pPriv->pDraw = NULL; - - if (!pPrev) - dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, - WinPriv->next); - else - pPrev->next = WinPriv->next; - tmp = WinPriv; - WinPriv = WinPriv->next; - free(tmp); - continue; - } - } - - pPrev = WinPriv; - WinPriv = WinPriv->next; - } - - if (ScreenPriv->ClipNotify) { - pScreen->ClipNotify = ScreenPriv->ClipNotify; - (*pScreen->ClipNotify) (pWin, dx, dy); - pScreen->ClipNotify = KdXVClipNotify; - } -} - -/**** Required XvScreenRec fields ****/ - -static Bool -KdXVCloseScreen(ScreenPtr pScreen) -{ - XvScreenPtr pxvs = GET_XV_SCREEN(pScreen); - KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen); - XvAdaptorPtr pa; - int c; - - if (!ScreenPriv) - return TRUE; - - pScreen->DestroyWindow = ScreenPriv->DestroyWindow; - pScreen->WindowExposures = ScreenPriv->WindowExposures; - pScreen->ClipNotify = ScreenPriv->ClipNotify; - pScreen->CloseScreen = ScreenPriv->CloseScreen; - -/* fprintf(stderr,"XV: Unwrapping screen funcs\n"); */ - - for (c = 0, pa = pxvs->pAdaptors; c < pxvs->nAdaptors; c++, pa++) { - KdXVFreeAdaptor(pa); - } - - free(pxvs->pAdaptors); - free(ScreenPriv); - - return pScreen->CloseScreen(pScreen); -} - -/**** XvAdaptorRec fields ****/ - -static int -KdXVPutVideo(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - KdScreenPriv(portPriv->screen->pScreen); - int result; - - /* No dumping video to pixmaps... For now anyhow */ - if (pDraw->type != DRAWABLE_WINDOW) { - pPort->pDraw = (DrawablePtr) NULL; - return BadAlloc; - } - - /* If we are changing windows, unregister our port in the old window */ - if (portPriv->pDraw && (portPriv->pDraw != pDraw)) - KdXVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - result = KdXVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - if (result != Success) - return result; - - portPriv->pDraw = pDraw; - portPriv->type = XvInputMask; - - /* save a copy of these parameters */ - portPriv->vid_x = vid_x; - portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; - portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - - /* make sure we have the most recent copy of the clientClip */ - KdXVCopyClip(portPriv, pGC); - - /* To indicate to the DI layer that we were successful */ - pPort->pDraw = pDraw; - - if (!pScreenPriv->enabled) - return Success; - - return (KdXVReputVideo(portPriv)); -} - -static int -KdXVPutStill(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - ScreenPtr pScreen = pDraw->pScreen; - - KdScreenPriv(pScreen); - KdScreenInfo *screen = pScreenPriv->screen; - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if (!pScreenPriv->enabled) - return Success; - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionInit(&ClipRegion, NullBox, 1); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = 0; - VPBox.y1 = 0; - VPBox.x2 = screen->width; - VPBox.y2 = screen->height; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - if (portPriv->pDraw) { - KdXVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - } - - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto PUT_STILL_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->PutStill) (portPriv->screen, pDraw, - vid_x, vid_y, WinBox.x1, WinBox.y1, - vid_w, vid_h, drw_w, drw_h, - &ClipRegion, - portPriv->DevPriv.ptr); - - if ((ret == Success) && - (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_STILLS)) { - - KdXVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - portPriv->isOn = XV_ON; - portPriv->pDraw = pDraw; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - portPriv->type = 0; /* no mask means it's transient and should - not be reput once it's removed */ - pPort->pDraw = pDraw; /* make sure we can get stop requests */ - } - - PUT_STILL_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -KdXVGetVideo(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - int result; - - KdScreenPriv(portPriv->screen->pScreen); - - /* No pixmaps... For now anyhow */ - if (pDraw->type != DRAWABLE_WINDOW) { - pPort->pDraw = (DrawablePtr) NULL; - return BadAlloc; - } - - /* If we are changing windows, unregister our port in the old window */ - if (portPriv->pDraw && (portPriv->pDraw != pDraw)) - KdXVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - - /* Register our port with the new window */ - result = KdXVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - if (result != Success) - return result; - - portPriv->pDraw = pDraw; - portPriv->type = XvOutputMask; - - /* save a copy of these parameters */ - portPriv->vid_x = vid_x; - portPriv->vid_y = vid_y; - portPriv->vid_w = vid_w; - portPriv->vid_h = vid_h; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - - /* make sure we have the most recent copy of the clientClip */ - KdXVCopyClip(portPriv, pGC); - - /* To indicate to the DI layer that we were successful */ - pPort->pDraw = pDraw; - - if (!pScreenPriv->enabled) - return Success; - - return (KdXVRegetVideo(portPriv)); -} - -static int -KdXVGetStill(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 vid_x, INT16 vid_y, - CARD16 vid_w, CARD16 vid_h, - INT16 drw_x, INT16 drw_y, CARD16 drw_w, CARD16 drw_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - ScreenPtr pScreen = pDraw->pScreen; - - KdScreenPriv(pScreen); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if (!pScreenPriv->enabled) - return Success; - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionInit(&ClipRegion, NullBox, 1); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if (portPriv->pDraw) { - KdXVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - } - - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto GET_STILL_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->GetStill) (portPriv->screen, pDraw, - vid_x, vid_y, WinBox.x1, WinBox.y1, - vid_w, vid_h, drw_w, drw_h, - &ClipRegion, - portPriv->DevPriv.ptr); - - GET_STILL_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -KdXVStopVideo(XvPortPtr pPort, DrawablePtr pDraw) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - KdScreenPriv(portPriv->screen->pScreen); - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - KdXVRemovePortFromWindow((WindowPtr) pDraw, portPriv); - - if (!pScreenPriv->enabled) - return Success; - - /* Must free resources. */ - - if (portPriv->isOn > XV_OFF) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, TRUE); - portPriv->isOn = XV_OFF; - } - - return Success; -} - -static int -KdXVSetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 value) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return ((*portPriv->AdaptorRec->SetPortAttribute) (portPriv->screen, - attribute, value, - portPriv->DevPriv.ptr)); -} - -static int -KdXVGetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 *p_value) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return ((*portPriv->AdaptorRec->GetPortAttribute) (portPriv->screen, - attribute, - (int *) p_value, - portPriv->DevPriv.ptr)); -} - -static int -KdXVQueryBestSize(XvPortPtr pPort, - CARD8 motion, - CARD16 vid_w, CARD16 vid_h, - CARD16 drw_w, CARD16 drw_h, - unsigned int *p_w, unsigned int *p_h) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - (*portPriv->AdaptorRec->QueryBestSize) (portPriv->screen, - (Bool) motion, vid_w, vid_h, drw_w, - drw_h, p_w, p_h, - portPriv->DevPriv.ptr); - - return Success; -} - -static int -KdXVPutImage(DrawablePtr pDraw, - XvPortPtr pPort, - GCPtr pGC, - INT16 src_x, INT16 src_y, - CARD16 src_w, CARD16 src_h, - INT16 drw_x, INT16 drw_y, - CARD16 drw_w, CARD16 drw_h, - XvImagePtr format, - unsigned char *data, Bool sync, CARD16 width, CARD16 height) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - ScreenPtr pScreen = pDraw->pScreen; - - KdScreenPriv(pScreen); - RegionRec WinRegion; - RegionRec ClipRegion; - BoxRec WinBox; - int ret = Success; - Bool clippedAway = FALSE; - - if (pDraw->type != DRAWABLE_WINDOW) - return BadAlloc; - - if (!pScreenPriv->enabled) - return Success; - - WinBox.x1 = pDraw->x + drw_x; - WinBox.y1 = pDraw->y + drw_y; - WinBox.x2 = WinBox.x1 + drw_w; - WinBox.y2 = WinBox.y1 + drw_h; - - RegionInit(&WinRegion, &WinBox, 1); - RegionInit(&ClipRegion, NullBox, 1); - RegionIntersect(&ClipRegion, &WinRegion, pGC->pCompositeClip); - - if (portPriv->AdaptorRec->flags & VIDEO_CLIP_TO_VIEWPORT) { - RegionRec VPReg; - BoxRec VPBox; - - VPBox.x1 = 0; - VPBox.y1 = 0; - VPBox.x2 = pScreen->width; - VPBox.y2 = pScreen->height; - - RegionInit(&VPReg, &VPBox, 1); - RegionIntersect(&ClipRegion, &ClipRegion, &VPReg); - RegionUninit(&VPReg); - } - - if (portPriv->pDraw) { - KdXVRemovePortFromWindow((WindowPtr) (portPriv->pDraw), portPriv); - } - - if (!RegionNotEmpty(&ClipRegion)) { - clippedAway = TRUE; - goto PUT_IMAGE_BAILOUT; - } - - ret = (*portPriv->AdaptorRec->PutImage) (portPriv->screen, pDraw, - src_x, src_y, WinBox.x1, WinBox.y1, - src_w, src_h, drw_w, drw_h, - format->id, data, width, height, - sync, &ClipRegion, - portPriv->DevPriv.ptr); - - if ((ret == Success) && - (portPriv->AdaptorRec->flags & VIDEO_OVERLAID_IMAGES)) { - - KdXVEnlistPortInWindow((WindowPtr) pDraw, portPriv); - portPriv->isOn = XV_ON; - portPriv->pDraw = pDraw; - portPriv->drw_x = drw_x; - portPriv->drw_y = drw_y; - portPriv->drw_w = drw_w; - portPriv->drw_h = drw_h; - portPriv->type = 0; /* no mask means it's transient and should - not be reput once it's removed */ - pPort->pDraw = pDraw; /* make sure we can get stop requests */ - } - - PUT_IMAGE_BAILOUT: - - if ((clippedAway || (ret != Success)) && (portPriv->isOn == XV_ON)) { - (*portPriv->AdaptorRec->StopVideo) (portPriv->screen, - portPriv->DevPriv.ptr, FALSE); - portPriv->isOn = XV_PENDING; - } - - RegionUninit(&WinRegion); - RegionUninit(&ClipRegion); - - return ret; -} - -static int -KdXVQueryImageAttributes(XvPortPtr pPort, - XvImagePtr format, - CARD16 *width, - CARD16 *height, int *pitches, int *offsets) -{ - XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr); - - return (*portPriv->AdaptorRec->QueryImageAttributes) (portPriv->screen, - format->id, width, - height, pitches, - offsets); -} diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h deleted file mode 100644 index a264dcab2..000000000 --- a/hw/kdrive/src/kxv.h +++ /dev/null @@ -1,197 +0,0 @@ -/* - - XFree86 Xv DDX written by Mark Vojkovich (markv@valinux.com) - Adapted for KDrive by Pontus Lidman - - Copyright (C) 2000, 2001 - Nokia Home Communications - Copyright (C) 1998, 1999 - The XFree86 Project Inc. - -All rights reserved. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, and/or sell copies of the Software, and to permit persons -to whom the Software is furnished to do so, provided that the above -copyright notice(s) and this permission notice appear in all copies of -the Software and that both the above copyright notice(s) and this -permission notice appear in supporting documentation. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY -SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER -RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF -CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -Except as contained in this notice, the name of a copyright holder -shall not be used in advertising or otherwise to promote the sale, use -or other dealings in this Software without prior written authorization -of the copyright holder. - -*/ - -#ifndef _XVDIX_H_ -#define _XVDIX_H_ - -#include "scrnintstr.h" -#include "regionstr.h" -#include "windowstr.h" -#include "pixmapstr.h" -#include "mivalidate.h" -#include "validate.h" -#include "resource.h" -#include "gcstruct.h" -#include "dixstruct.h" - -#include "../../Xext/xvdix.h" - -#define VIDEO_OVERLAID_IMAGES 0x00000004 -#define VIDEO_OVERLAID_STILLS 0x00000008 -#define VIDEO_CLIP_TO_VIEWPORT 0x00000010 - -typedef int (*PutVideoFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw, - short vid_x, short vid_y, short drw_x, - short drw_y, short vid_w, short vid_h, - short drw_w, short drw_h, RegionPtr clipBoxes, - void *data); -typedef int (*PutStillFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw, - short vid_x, short vid_y, short drw_x, - short drw_y, short vid_w, short vid_h, - short drw_w, short drw_h, RegionPtr clipBoxes, - void *data); -typedef int (*GetVideoFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw, - short vid_x, short vid_y, short drw_x, - short drw_y, short vid_w, short vid_h, - short drw_w, short drw_h, RegionPtr clipBoxes, - void *data); -typedef int (*GetStillFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw, - short vid_x, short vid_y, short drw_x, - short drw_y, short vid_w, short vid_h, - short drw_w, short drw_h, RegionPtr clipBoxes, - void *data); -typedef void (*StopVideoFuncPtr) (KdScreenInfo * screen, void *data, - Bool Exit); -typedef int (*SetPortAttributeFuncPtr) (KdScreenInfo * screen, Atom attribute, - int value, void *data); -typedef int (*GetPortAttributeFuncPtr) (KdScreenInfo * screen, Atom attribute, - int *value, void *data); -typedef void (*QueryBestSizeFuncPtr) (KdScreenInfo * screen, Bool motion, - short vid_w, short vid_h, short drw_w, - short drw_h, unsigned int *p_w, - unsigned int *p_h, void *data); -typedef int (*PutImageFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw, - short src_x, short src_y, short drw_x, - short drw_y, short src_w, short src_h, - short drw_w, short drw_h, int image, - unsigned char *buf, short width, short height, - Bool Sync, RegionPtr clipBoxes, void *data); -typedef int (*ReputImageFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw, - short drw_x, short drw_y, RegionPtr clipBoxes, - void *data); -typedef int (*QueryImageAttributesFuncPtr) (KdScreenInfo * screen, int image, - unsigned short *width, - unsigned short *height, - int *pitches, int *offsets); - -typedef enum { - XV_OFF, - XV_PENDING, - XV_ON -} XvStatus; - -/*** this is what the driver needs to fill out ***/ - -typedef struct { - int id; - const char *name; - unsigned short width, height; - XvRationalRec rate; -} KdVideoEncodingRec, *KdVideoEncodingPtr; - -typedef struct { - char depth; - short class; -} KdVideoFormatRec, *KdVideoFormatPtr; - -typedef struct { - unsigned int type; - int flags; - const char *name; - int nEncodings; - KdVideoEncodingPtr pEncodings; - int nFormats; - KdVideoFormatPtr pFormats; - int nPorts; - DevUnion *pPortPrivates; - int nAttributes; - XvAttributePtr pAttributes; - int nImages; - XvImagePtr pImages; - PutVideoFuncPtr PutVideo; - PutStillFuncPtr PutStill; - GetVideoFuncPtr GetVideo; - GetStillFuncPtr GetStill; - StopVideoFuncPtr StopVideo; - SetPortAttributeFuncPtr SetPortAttribute; - GetPortAttributeFuncPtr GetPortAttribute; - QueryBestSizeFuncPtr QueryBestSize; - PutImageFuncPtr PutImage; - ReputImageFuncPtr ReputImage; - QueryImageAttributesFuncPtr QueryImageAttributes; -} KdVideoAdaptorRec, *KdVideoAdaptorPtr; - -Bool - KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr Adaptors, int num); - -/*** These are DDX layer privates ***/ - -typedef struct { - DestroyWindowProcPtr DestroyWindow; - ClipNotifyProcPtr ClipNotify; - WindowExposuresProcPtr WindowExposures; - CloseScreenProcPtr CloseScreen; -} KdXVScreenRec, *KdXVScreenPtr; - -typedef struct { - int flags; - PutVideoFuncPtr PutVideo; - PutStillFuncPtr PutStill; - GetVideoFuncPtr GetVideo; - GetStillFuncPtr GetStill; - StopVideoFuncPtr StopVideo; - SetPortAttributeFuncPtr SetPortAttribute; - GetPortAttributeFuncPtr GetPortAttribute; - QueryBestSizeFuncPtr QueryBestSize; - PutImageFuncPtr PutImage; - ReputImageFuncPtr ReputImage; - QueryImageAttributesFuncPtr QueryImageAttributes; -} XvAdaptorRecPrivate, *XvAdaptorRecPrivatePtr; - -typedef struct { - KdScreenInfo *screen; - DrawablePtr pDraw; - unsigned char type; - unsigned int subWindowMode; - DDXPointRec clipOrg; - RegionPtr clientClip; - RegionPtr pCompositeClip; - Bool FreeCompositeClip; - XvAdaptorRecPrivatePtr AdaptorRec; - XvStatus isOn; - Bool moved; - int vid_x, vid_y, vid_w, vid_h; - int drw_x, drw_y, drw_w, drw_h; - DevUnion DevPriv; -} XvPortRecPrivate, *XvPortRecPrivatePtr; - -typedef struct _KdXVWindowRec { - XvPortRecPrivatePtr PortRec; - struct _KdXVWindowRec *next; -} KdXVWindowRec, *KdXVWindowPtr; - -#endif /* _XVDIX_H_ */ diff --git a/hw/kdrive/src/meson.build b/hw/kdrive/src/meson.build deleted file mode 100644 index fbc0727e9..000000000 --- a/hw/kdrive/src/meson.build +++ /dev/null @@ -1,20 +0,0 @@ -srcs_kdrive = [ - 'kcmap.c', - 'kdrive.c', - 'kinfo.c', - 'kinput.c', - 'kshadow.c', - '../../../mi/miinitext.c', - '../../../mi/miinitext.h', -] - -if build_xv - srcs_kdrive += 'kxv.c' -endif - -kdrive = static_library('kdrive', - srcs_kdrive, - include_directories: inc, - dependencies: common_dep, - link_with: libxserver_miext_shadow, -) diff --git a/hw/meson.build b/hw/meson.build index 6fd83a6b9..e2e27b3ed 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -1,7 +1,3 @@ -if get_option('xephyr') - subdir('kdrive') -endif - if get_option('xvfb') subdir('vfb') endif diff --git a/meson.build b/meson.build index 2368aa172..1ba9ae770 100644 --- a/meson.build +++ b/meson.build @@ -566,9 +566,6 @@ subdir('Xi') if build_glamor subdir('glamor') endif -if get_option('xephyr') - subdir('exa') -endif # Common static libraries of all X servers libxserver = [ diff --git a/meson_options.txt b/meson_options.txt index 7e891997f..c02766ce0 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,5 +1,3 @@ -option('xephyr', type: 'boolean', value: false, - description: 'Enable Xephyr nested X server') option('xwayland', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', description: 'Enable XWayland X server') option('glamor', type: 'combo', choices: ['true', 'false', 'auto'], value: 'auto', diff --git a/test/meson.build b/test/meson.build index bfa5af4d9..076bb35f9 100644 --- a/test/meson.build +++ b/test/meson.build @@ -68,36 +68,6 @@ if get_option('xvfb') ) endforeach endif - - if get_option('xephyr') and build_glamor - test('XTS', - find_program('scripts/xephyr-glamor-piglit.sh'), - env: piglit_env, - timeout: 1200, - suite: 'xephr-glamor', - ) - - if rendercheck.found() - foreach rctest: rendercheck_tests - test(rctest[0], - simple_xinit, - args: [simple_xinit.full_path(), - rendercheck.path(), - rctest[1].split(' '), - '----', - xephyr_server.full_path(), - '-glamor', - '-glamor-skip-present', - '-schedMax', '2000', - '--', - xvfb_args, - ], - suite: 'xephr-glamor', - timeout: 300, - ) - endforeach - endif - endif endif if build_xwayland diff --git a/test/scripts/xephyr-glamor-piglit.sh b/test/scripts/xephyr-glamor-piglit.sh deleted file mode 100755 index 0458f271b..000000000 --- a/test/scripts/xephyr-glamor-piglit.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -# this times out on Travis, because the tests take too long. -if test "x$TRAVIS_BUILD_DIR" != "x"; then - exit 77 -fi - -# Start a Xephyr server using glamor. Since the test environment is -# headless, we start an Xvfb first to host the Xephyr. -export PIGLIT_RESULTS_DIR=$XSERVER_BUILDDIR/test/piglit-results/xephyr-glamor - -export SERVER_COMMAND="$XSERVER_BUILDDIR/hw/kdrive/ephyr/Xephyr \ - -glamor \ - -glamor-skip-present \ - -noreset \ - -schedMax 2000 \ - -screen 1280x1024" - -# Tests that currently fail on llvmpipe on CI -PIGLIT_ARGS="$PIGLIT_ARGS -x xcleararea@6" -PIGLIT_ARGS="$PIGLIT_ARGS -x xcleararea@7" -PIGLIT_ARGS="$PIGLIT_ARGS -x xclearwindow@4" -PIGLIT_ARGS="$PIGLIT_ARGS -x xclearwindow@5" -PIGLIT_ARGS="$PIGLIT_ARGS -x xcopyarea@1" - -export PIGLIT_ARGS - -$XSERVER_BUILDDIR/test/simple-xinit \ - $XSERVER_DIR/test/scripts/run-piglit.sh \ - -- \ - $XSERVER_BUILDDIR/hw/vfb/Xvfb \ - -screen scrn 1280x1024x24