diff options
Diffstat (limited to 'xorg-server/hw/kdrive')
20 files changed, 1686 insertions, 4164 deletions
diff --git a/xorg-server/hw/kdrive/ephyr/Makefile.am b/xorg-server/hw/kdrive/ephyr/Makefile.am index ab024373c..6b790fddd 100644 --- a/xorg-server/hw/kdrive/ephyr/Makefile.am +++ b/xorg-server/hw/kdrive/ephyr/Makefile.am @@ -1,3 +1,24 @@ +# 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. + SUBDIRS = man AM_CPPFLAGS = \ @@ -9,81 +30,45 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/exa if XV -LIBXEPHYR_HOSTXV=libxephyr-hostxv.la +XV_SRCS = ephyrvideo.c endif if DRI -LIBXEPHYR_HOSTDRI=libxephyr-hostdri.la -endif - -noinst_LTLIBRARIES = libxephyr-hostx.la $(LIBXEPHYR_HOSTXV) $(LIBXEPHYR_HOSTDRI) libxephyr.la - -bin_PROGRAMS = Xephyr - -HOSTX_SRCS = \ - hostx.c \ - hostx.h - -HOSTVIDEO_SRCS = \ - ephyrvideo.c \ - ephyrhostvideo.c \ - ephyrhostvideo.h - -HOSTDRI_SRCS = \ +DRI_SRCS = \ ephyrdriext.c \ ephyrdriext.h \ ephyrdri.c \ ephyrdri.h \ - XF86dri.c \ - xf86dri.h \ ephyrglxext.c \ ephyrglxext.h \ ephyrhostglx.c \ - ephyrhostglx.h - -XEPHYR_SRCS = \ - ephyr.c \ - ephyr.h \ - ephyrlog.h \ - ephyr_draw.c \ - os.c - -libxephyr_hostx_la_SOURCES = $(HOSTX_SRCS) - -if XV -libxephyr_hostxv_la_SOURCES = $(HOSTVIDEO_SRCS) -endif - -if DRI -libxephyr_hostdri_la_SOURCES = $(HOSTDRI_SRCS) + ephyrhostglx.h \ + $() endif -libxephyr_la_SOURCES = $(XEPHYR_SRCS) +bin_PROGRAMS = Xephyr Xephyr_SOURCES = \ - ephyrinit.c + ephyr.c \ + ephyr.h \ + ephyrlog.h \ + ephyr_draw.c \ + os.c \ + ephyrinit.c \ + hostx.c \ + hostx.h \ + $(XV_SRCS) \ + $(DRI_SRCS) \ + $() Xephyr_LDADD = \ - libxephyr.la \ - libxephyr-hostx.la \ - $(LIBXEPHYR_HOSTXV) \ - $(LIBXEPHYR_HOSTDRI) \ $(top_builddir)/exa/libexa.la \ @KDRIVE_LIBS@ \ @XEPHYR_LIBS@ -Xephyr_DEPENDENCIES = \ - libxephyr.la \ - libxephyr-hostx.la \ - $(LIBXEPHYR_HOSTXV) \ - $(LIBXEPHYR_HOSTDRI) \ - @KDRIVE_LOCAL_LIBS@ +Xephyr_DEPENDENCIES = @KDRIVE_LOCAL_LIBS@ Xephyr_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG) relink: $(AM_V_at)rm -f $(bin_PROGRAMS) && $(MAKE) $(bin_PROGRAMS) - -EXTRA_DIST = \ - $(HOSTVIDEO_SRCS) \ - $(HOSTDRI_SRCS) diff --git a/xorg-server/hw/kdrive/ephyr/XF86dri.c b/xorg-server/hw/kdrive/ephyr/XF86dri.c deleted file mode 100644 index 15b62191f..000000000 --- a/xorg-server/hw/kdrive/ephyr/XF86dri.c +++ /dev/null @@ -1,654 +0,0 @@ -/* $XFree86: xc/lib/GL/dri/XF86dri.c,v 1.13 2002/10/30 12:51:25 alanh Exp $ */ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -Copyright 2000 VA Linux Systems, 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, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin <martin@valinux.com> - * Jens Owen <jens@tungstengraphics.com> - * Rickard E. (Rik) Faith <faith@valinux.com> - * - */ - -/* - * This file has been copied from the mesa source tree and a little bit - * modified by: - * - * Dodji Seketeli <dodji@openedhand.com> - */ - -#ifdef HAVE_CONFIG_H -#include <kdrive-config.h> -#endif -/* - * including some server headers (like kdrive-config.h) - * might define the macro _XSERVER64 - * on 64 bits machines. That macro must _NOT_ be defined for Xlib - * client code, otherwise bad things happen. - * So let's undef that macro if necessary. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - -/* THIS IS NOT AN X CONSORTIUM STANDARD */ - -#include <X11/Xlibint.h> -#include <X11/extensions/Xext.h> -#include <X11/extensions/extutil.h> -#include <GL/glx.h> -#include "xf86dri.h" -#include <X11/dri/xf86driproto.h> -#include <limits.h> - -static XExtensionInfo _xf86dri_info_data; -static XExtensionInfo *xf86dri_info = &_xf86dri_info_data; -static char xf86dri_extension_name[] = XF86DRINAME; - -#define XF86DRICheckExtension(dpy,i,val) \ - XextCheckExtension (dpy, i, xf86dri_extension_name, val) - -/***************************************************************************** - * * - * private utility routines * - * * - *****************************************************************************/ - -static int close_display(Display * dpy, XExtCodes * extCodes); - -static /* const */ XExtensionHooks xf86dri_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - close_display, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ -}; - -static -XEXT_GENERATE_FIND_DISPLAY(find_display, xf86dri_info, - xf86dri_extension_name, - &xf86dri_extension_hooks, 0, NULL) - -static -XEXT_GENERATE_CLOSE_DISPLAY(close_display, xf86dri_info) - -/***************************************************************************** - * * - * public XFree86-DRI Extension routines * - * * - *****************************************************************************/ -#if 0 -#include <stdio.h> -#define TRACE(msg) fprintf(stderr,"XF86DRI%s\n", msg); -#else -#define TRACE(msg) -#endif -Bool -XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable); -Bool -XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable); - -Bool -XF86DRIQueryExtension(Display * dpy, int *event_basep, int *error_basep) -{ - XExtDisplayInfo *info = find_display(dpy); - - TRACE("QueryExtension..."); - if (XextHasExtension(info)) { - *event_basep = info->codes->first_event; - *error_basep = info->codes->first_error; - TRACE("QueryExtension... return True"); - return True; - } - else { - TRACE("QueryExtension... return False"); - return False; - } -} - -Bool -XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion, - int *patchVersion) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIQueryVersionReply rep; - xXF86DRIQueryVersionReq *req; - - TRACE("QueryVersion..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIQueryVersion, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIQueryVersion; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("QueryVersion... return False"); - return False; - } - *majorVersion = rep.majorVersion; - *minorVersion = rep.minorVersion; - *patchVersion = rep.patchVersion; - UnlockDisplay(dpy); - SyncHandle(); - TRACE("QueryVersion... return True"); - return True; -} - -Bool -XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen, Bool *isCapable) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIQueryDirectRenderingCapableReply rep; - xXF86DRIQueryDirectRenderingCapableReq *req; - - TRACE("QueryDirectRenderingCapable..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIQueryDirectRenderingCapable, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIQueryDirectRenderingCapable; - req->screen = screen; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("QueryDirectRenderingCapable... return False"); - return False; - } - *isCapable = rep.isCapable; - UnlockDisplay(dpy); - SyncHandle(); - TRACE("QueryDirectRenderingCapable... return True"); - return True; -} - -Bool -XF86DRIOpenConnection(Display * dpy, int screen, - drm_handle_t * hSAREA, char **busIdString) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIOpenConnectionReply rep; - xXF86DRIOpenConnectionReq *req; - - TRACE("OpenConnection..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIOpenConnection, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIOpenConnection; - req->screen = screen; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("OpenConnection... return False"); - return False; - } - - *hSAREA = rep.hSAREALow; - if (sizeof(drm_handle_t) == 8) { - int shift = 32; /* var to prevent warning on next line */ - - *hSAREA |= ((drm_handle_t) rep.hSAREAHigh) << shift; - } - - if (rep.length) { - if (rep.busIdStringLength < INT_MAX) - *busIdString = calloc(rep.busIdStringLength + 1, 1); - else - *busIdString = NULL; - if (*busIdString == NULL) { - _XEatDataWords(dpy, rep.length); - UnlockDisplay(dpy); - SyncHandle(); - TRACE("OpenConnection... return False"); - return False; - } - _XReadPad(dpy, *busIdString, rep.busIdStringLength); - } - else { - *busIdString = NULL; - } - UnlockDisplay(dpy); - SyncHandle(); - TRACE("OpenConnection... return True"); - return True; -} - -Bool -XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIAuthConnectionReq *req; - xXF86DRIAuthConnectionReply rep; - - TRACE("AuthConnection..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIAuthConnection, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIAuthConnection; - req->screen = screen; - req->magic = magic; - rep.authenticated = 0; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse) || !rep.authenticated) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("AuthConnection... return False"); - return False; - } - UnlockDisplay(dpy); - SyncHandle(); - TRACE("AuthConnection... return True"); - return True; -} - -Bool -XF86DRICloseConnection(Display * dpy, int screen) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRICloseConnectionReq *req; - - TRACE("CloseConnection..."); - - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRICloseConnection, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRICloseConnection; - req->screen = screen; - UnlockDisplay(dpy); - SyncHandle(); - TRACE("CloseConnection... return True"); - return True; -} - -Bool -XF86DRIGetClientDriverName(Display * dpy, int screen, - int *ddxDriverMajorVersion, - int *ddxDriverMinorVersion, - int *ddxDriverPatchVersion, char **clientDriverName) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIGetClientDriverNameReply rep; - xXF86DRIGetClientDriverNameReq *req; - - TRACE("GetClientDriverName..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIGetClientDriverName, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIGetClientDriverName; - req->screen = screen; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetClientDriverName... return False"); - return False; - } - - *ddxDriverMajorVersion = rep.ddxDriverMajorVersion; - *ddxDriverMinorVersion = rep.ddxDriverMinorVersion; - *ddxDriverPatchVersion = rep.ddxDriverPatchVersion; - - if (rep.length) { - if (rep.clientDriverNameLength < INT_MAX) - *clientDriverName = calloc(rep.clientDriverNameLength + 1, 1); - else - *clientDriverName = NULL; - if (*clientDriverName == NULL) { - _XEatDataWords(dpy, rep.length); - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetClientDriverName... return False"); - return False; - } - _XReadPad(dpy, *clientDriverName, rep.clientDriverNameLength); - } - else { - *clientDriverName = NULL; - } - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetClientDriverName... return True"); - return True; -} - -Bool -XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID, - XID *context, drm_context_t * hHWContext) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRICreateContextReply rep; - xXF86DRICreateContextReq *req; - - TRACE("CreateContext..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRICreateContext, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRICreateContext; - req->visual = configID; - req->screen = screen; - *context = XAllocID(dpy); - req->context = *context; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("CreateContext... return False"); - return False; - } - *hHWContext = rep.hHWContext; - UnlockDisplay(dpy); - SyncHandle(); - TRACE("CreateContext... return True"); - return True; -} - -Bool -XF86DRICreateContext(Display * dpy, int screen, Visual * visual, - XID *context, drm_context_t * hHWContext) -{ - return XF86DRICreateContextWithConfig(dpy, screen, visual->visualid, - context, hHWContext); -} - -GLboolean -XF86DRIDestroyContext(Display * dpy, int screen, XID context) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIDestroyContextReq *req; - - TRACE("DestroyContext..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIDestroyContext, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIDestroyContext; - req->screen = screen; - req->context = context; - UnlockDisplay(dpy); - SyncHandle(); - TRACE("DestroyContext... return True"); - return True; -} - -GLboolean -XF86DRICreateDrawable(Display * dpy, int screen, - XID drawable, drm_drawable_t * hHWDrawable) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRICreateDrawableReply rep; - xXF86DRICreateDrawableReq *req; - - TRACE("CreateDrawable..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRICreateDrawable, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRICreateDrawable; - req->screen = screen; - req->drawable = drawable; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("CreateDrawable... return False"); - return False; - } - *hHWDrawable = rep.hHWDrawable; - UnlockDisplay(dpy); - SyncHandle(); - TRACE("CreateDrawable... return True"); - return True; -} - -static int -noopErrorHandler(Display * dpy, XErrorEvent * xerr) -{ - return 0; -} - -GLboolean -XF86DRIDestroyDrawable(Display * dpy, int screen, XID drawable) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIDestroyDrawableReq *req; - int (*oldXErrorHandler) (Display *, XErrorEvent *); - - TRACE("DestroyDrawable..."); - XF86DRICheckExtension(dpy, info, False); - - /* This is called from the DRI driver, which used call it like this - * - * if (windowExists(drawable)) - * destroyDrawable(drawable); - * - * which is a textbook race condition - the window may disappear - * from the server between checking for its existance and - * destroying it. Instead we change the semantics of - * __DRIinterfaceMethodsRec::destroyDrawable() to succeed even if - * the windows is gone, by wrapping the destroy call in an error - * handler. */ - - XSync(dpy, GL_FALSE); - oldXErrorHandler = XSetErrorHandler(noopErrorHandler); - - LockDisplay(dpy); - GetReq(XF86DRIDestroyDrawable, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIDestroyDrawable; - req->screen = screen; - req->drawable = drawable; - UnlockDisplay(dpy); - SyncHandle(); - - XSetErrorHandler(oldXErrorHandler); - - TRACE("DestroyDrawable... return True"); - return True; -} - -Bool -XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable, - unsigned int *index, unsigned int *stamp, - int *X, int *Y, int *W, int *H, - int *numClipRects, drm_clip_rect_t ** pClipRects, - int *backX, int *backY, - int *numBackClipRects, drm_clip_rect_t ** pBackClipRects) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIGetDrawableInfoReply rep; - xXF86DRIGetDrawableInfoReq *req = NULL; - int total_rects; - - TRACE("GetDrawableInfo..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIGetDrawableInfo, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIGetDrawableInfo; - req->screen = screen; - req->drawable = drawable; - - if (!_XReply(dpy, (xReply *) &rep, 1, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetDrawableInfo... return False"); - return False; - } - *index = rep.drawableTableIndex; - *stamp = rep.drawableTableStamp; - *X = (int) rep.drawableX; - *Y = (int) rep.drawableY; - *W = (int) rep.drawableWidth; - *H = (int) rep.drawableHeight; - *numClipRects = rep.numClipRects; - total_rects = *numClipRects; - - *backX = rep.backX; - *backY = rep.backY; - *numBackClipRects = rep.numBackClipRects; - total_rects += *numBackClipRects; - -#if 0 - /* Because of the fix in Xserver/GL/dri/xf86dri.c, this check breaks - * backwards compatibility (Because of the >> 2 shift) but the fix - * enables multi-threaded apps to work. - */ - if (rep.length != ((((SIZEOF(xXF86DRIGetDrawableInfoReply) - - SIZEOF(xGenericReply) + - total_rects * sizeof(drm_clip_rect_t)) + - 3) & ~3) >> 2)) { - _XEatDataWords(dpy, rep.length); - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetDrawableInfo... return False"); - return False; - } -#endif - - if (*numClipRects) { - int len = sizeof(drm_clip_rect_t) * (*numClipRects); - - *pClipRects = (drm_clip_rect_t *) calloc(len, 1); - if (*pClipRects) - _XRead(dpy, (char *) *pClipRects, len); - } - else { - *pClipRects = NULL; - } - - if (*numBackClipRects) { - int len = sizeof(drm_clip_rect_t) * (*numBackClipRects); - - *pBackClipRects = (drm_clip_rect_t *) calloc(len, 1); - if (*pBackClipRects) - _XRead(dpy, (char *) *pBackClipRects, len); - } - else { - *pBackClipRects = NULL; - } - - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetDrawableInfo... return True"); - return True; -} - -Bool -XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer, - int *fbOrigin, int *fbSize, int *fbStride, - int *devPrivateSize, void **pDevPrivate) -{ - XExtDisplayInfo *info = find_display(dpy); - xXF86DRIGetDeviceInfoReply rep; - xXF86DRIGetDeviceInfoReq *req; - - TRACE("GetDeviceInfo..."); - XF86DRICheckExtension(dpy, info, False); - - LockDisplay(dpy); - GetReq(XF86DRIGetDeviceInfo, req); - req->reqType = info->codes->major_opcode; - req->driReqType = X_XF86DRIGetDeviceInfo; - req->screen = screen; - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetDeviceInfo... return False"); - return False; - } - - *hFrameBuffer = rep.hFrameBufferLow; - if (sizeof(drm_handle_t) == 8) { - int shift = 32; /* var to prevent warning on next line */ - - *hFrameBuffer |= ((drm_handle_t) rep.hFrameBufferHigh) << shift; - } - - *fbOrigin = rep.framebufferOrigin; - *fbSize = rep.framebufferSize; - *fbStride = rep.framebufferStride; - *devPrivateSize = rep.devPrivateSize; - - if (rep.length) { - if (!(*pDevPrivate = (void *) calloc(rep.devPrivateSize, 1))) { - _XEatDataWords(dpy, rep.length); - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetDeviceInfo... return False"); - return False; - } - _XRead(dpy, (char *) *pDevPrivate, rep.devPrivateSize); - } - else { - *pDevPrivate = NULL; - } - - UnlockDisplay(dpy); - SyncHandle(); - TRACE("GetDeviceInfo... return True"); - return True; -} - -Bool -XF86DRIOpenFullScreen(Display * dpy, int screen, Drawable drawable) -{ - /* This function and the underlying X protocol are deprecated. - */ - (void) dpy; - (void) screen; - (void) drawable; - return False; -} - -Bool -XF86DRICloseFullScreen(Display * dpy, int screen, Drawable drawable) -{ - /* This function and the underlying X protocol are deprecated. - */ - (void) dpy; - (void) screen; - (void) drawable; - return True; -} diff --git a/xorg-server/hw/kdrive/ephyr/ephyr.c b/xorg-server/hw/kdrive/ephyr/ephyr.c index 02d497073..a603ef734 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyr.c +++ b/xorg-server/hw/kdrive/ephyr/ephyr.c @@ -26,6 +26,10 @@ #ifdef HAVE_CONFIG_H #include <kdrive-config.h> #endif + +#include <xcb/xcb_keysyms.h> +#include <X11/keysym.h> + #include "ephyr.h" #include "inputstr.h" @@ -33,6 +37,7 @@ #include "ephyrlog.h" #ifdef XF86DRI +#include <xcb/xf86dri.h> #include "ephyrdri.h" #include "ephyrdriext.h" #include "ephyrglxext.h" @@ -59,6 +64,16 @@ Bool EphyrWantGrayScale = 0; Bool EphyrWantResize = 0; Bool +host_has_extension(xcb_extension_t *extension) +{ + const xcb_query_extension_reply_t *rep; + + rep = xcb_get_extension_data(hostx_get_xcbconn(), extension); + + return rep && rep->present; +} + +Bool ephyrInitialize(KdCardInfo * card, EphyrPriv * priv) { OsSignal(SIGUSR1, hostx_handle_signal); @@ -87,8 +102,9 @@ ephyrCardInit(KdCardInfo * card) } Bool -ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv) +ephyrScreenInitialize(KdScreenInfo *screen) { + EphyrScrPriv *scrpriv = screen->driver; int width = 640, height = 480; CARD32 redMask, greenMask, blueMask; @@ -105,7 +121,7 @@ ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv) if (screen->fb.depth < hostx_get_depth() && (screen->fb.depth == 24 || screen->fb.depth == 16 || screen->fb.depth == 8)) { - hostx_set_server_depth(screen, screen->fb.depth); + scrpriv->server_depth = screen->fb.depth; } else ErrorF @@ -168,27 +184,6 @@ ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv) return ephyrMapFramebuffer(screen); } -Bool -ephyrScreenInit(KdScreenInfo * screen) -{ - EphyrScrPriv *scrpriv; - - scrpriv = calloc(1, sizeof(EphyrScrPriv)); - - if (!scrpriv) - return FALSE; - - screen->driver = scrpriv; - - if (!ephyrScreenInitialize(screen, scrpriv)) { - screen->driver = 0; - free(scrpriv); - return FALSE; - } - - return TRUE; -} - void * ephyrWindowLinear(ScreenPtr pScreen, CARD32 row, @@ -389,10 +384,7 @@ ephyrUnsetInternalDamage(ScreenPtr pScreen) KdScreenPriv(pScreen); KdScreenInfo *screen = pScreenPriv->screen; EphyrScrPriv *scrpriv = screen->driver; - PixmapPtr pPixmap = NULL; - pPixmap = (*pScreen->GetScreenPixmap) (pScreen); - DamageUnregister(&pPixmap->drawable, scrpriv->pDamage); DamageDestroy(scrpriv->pDamage); RemoveBlockAndWakeupHandlers(ephyrInternalDamageBlockHandler, @@ -657,7 +649,7 @@ ephyrInitScreen(ScreenPtr pScreen) } #endif /*XV*/ #ifdef XF86DRI - if (!ephyrNoDRI && !hostx_has_dri()) { + if (!ephyrNoDRI && !host_has_extension(&xcb_xf86dri_id)) { EPHYR_LOG("host x does not support DRI. Disabling DRI forwarding\n"); ephyrNoDRI = TRUE; } @@ -807,13 +799,13 @@ ephyrCrossScreen(ScreenPtr pScreen, Bool entering) { } -int ephyrCurScreen; /*current event screen */ +ScreenPtr ephyrCursorScreen; /* screen containing the cursor */ static void ephyrWarpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y) { OsBlockSIGIO(); - ephyrCurScreen = pScreen->myNum; + ephyrCursorScreen = pScreen; miPointerWarpCursor(inputInfo.pointer, pScreen, x, y); OsReleaseSIGIO(); @@ -823,8 +815,6 @@ miPointerScreenFuncRec ephyrPointerScreenFuncs = { ephyrCursorOffScreen, ephyrCrossScreen, ephyrWarpCursor, - NULL, - NULL }; #ifdef XF86DRI @@ -861,123 +851,327 @@ ephyrExposePairedWindow(int a_remote) } #endif /* XF86DRI */ -void -ephyrPoll(void) +static KdScreenInfo * +screen_from_window(Window w) { - EphyrHostXEvent ev; - - while (hostx_get_event(&ev)) { - switch (ev.type) { - case EPHYR_EV_MOUSE_MOTION: - if (!ephyrMouse || - !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) { - EPHYR_LOG("skipping mouse motion:%d\n", ephyrCurScreen); - continue; - } - { - if (ev.data.mouse_motion.screen >= 0 - && (ephyrCurScreen != ev.data.mouse_motion.screen)) { - EPHYR_LOG("warping mouse cursor. " - "cur_screen%d, motion_screen:%d\n", - ephyrCurScreen, ev.data.mouse_motion.screen); - if (ev.data.mouse_motion.screen >= 0) { - ephyrWarpCursor - (inputInfo.pointer, - screenInfo.screens[ev.data.mouse_motion.screen], - ev.data.mouse_motion.x, ev.data.mouse_motion.y); - } - } - else { - int x = 0, y = 0; + 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"); #ifdef XF86DRI - EphyrWindowPair *pair = NULL; + /* + * We only receive expose events when the expose event + * have be generated for a drawable that is a host X + * window managed by Xephyr. Host X windows managed by + * Xephyr exists for instance when Xephyr is asked to + * create a GL drawable in a DRI environment. + */ + ephyrExposePairedWindow(expose->window); +#endif /* XF86DRI */ + } +} + +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, screen->pScreen->myNum); + ephyrWarpCursor(inputInfo.pointer, screen->pScreen, + motion->event_x, motion->event_y); + } + else { + int x = 0, y = 0; + +#ifdef XF86DRI + EphyrWindowPair *pair = NULL; #endif - EPHYR_LOG("enqueuing mouse motion:%d\n", ephyrCurScreen); - x = ev.data.mouse_motion.x; - y = ev.data.mouse_motion.y; - EPHYR_LOG("initial (x,y):(%d,%d)\n", x, y); + EPHYR_LOG("enqueuing mouse motion:%d\n", ephyrCurScreen); + x = motion->event_x; + y = motion->event_y; + EPHYR_LOG("initial (x,y):(%d,%d)\n", x, y); #ifdef XF86DRI - EPHYR_LOG("is this window peered by a gl drawable ?\n"); - if (findWindowPairFromRemote(ev.data.mouse_motion.window, - &pair)) { - EPHYR_LOG("yes, it is peered\n"); - x += pair->local->drawable.x; - y += pair->local->drawable.y; - } - else { - EPHYR_LOG("no, it is not peered\n"); - } - EPHYR_LOG("final (x,y):(%d,%d)\n", x, y); + EPHYR_LOG("is this window peered by a gl drawable ?\n"); + if (findWindowPairFromRemote(motion->event, &pair)) { + EPHYR_LOG("yes, it is peered\n"); + x += pair->local->drawable.x; + y += pair->local->drawable.y; + } + else { + EPHYR_LOG("no, it is not peered\n"); + } + EPHYR_LOG("final (x,y):(%d,%d)\n", x, y); #endif - KdEnqueuePointerEvent(ephyrMouse, mouseState, x, y, 0); + KdEnqueuePointerEvent(ephyrMouse, mouseState, 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", ephyrCurScreen); + 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", ephyrCurScreen); + 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", ephyrCurScreen); + KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0); +} + +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; + } + + 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; + + if (!keysyms) + keysyms = xcb_key_symbols_alloc(conn); + + if (((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 { + /* 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)"); } } - break; + } + } + + 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; - case EPHYR_EV_MOUSE_PRESS: - if (!ephyrMouse || - !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) { - EPHYR_LOG("skipping mouse press:%d\n", ephyrCurScreen); - continue; + if (!scrpriv || + (scrpriv->win_pre_existing == None && !EphyrWantResize)) { + return; + } + +#ifdef RANDR + ephyrResizeScreen(screen->pScreen, configure->width, configure->height); +#endif /* RANDR */ +} + +void +ephyrPoll(void) +{ + xcb_connection_t *conn = hostx_get_xcbconn(); + + while (TRUE) { + xcb_generic_event_t *xev = xcb_poll_for_event(conn); + 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); } - EPHYR_LOG("enqueuing mouse press:%d\n", ephyrCurScreen); - ephyrUpdateModifierState(ev.key_state); - mouseState |= ev.data.mouse_down.button_num; - KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, - 0); + break; + } - case EPHYR_EV_MOUSE_RELEASE: - if (!ephyrMouse || - !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) - continue; - ephyrUpdateModifierState(ev.key_state); - mouseState &= ~ev.data.mouse_up.button_num; - EPHYR_LOG("enqueuing mouse release:%d\n", ephyrCurScreen); - KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, - 0); + switch (xev->response_type & 0x7f) { + case 0: + ephyrProcessErrorEvent(xev); break; - case EPHYR_EV_KEY_PRESS: - if (!ephyrKbd || - !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled) - continue; - ephyrUpdateModifierState(ev.key_state); - KdEnqueueKeyboardEvent(ephyrKbd, ev.data.key_down.scancode, FALSE); + case XCB_EXPOSE: + ephyrProcessExpose(xev); break; - case EPHYR_EV_KEY_RELEASE: - if (!ephyrKbd || - !((EphyrKbdPrivate *) ephyrKbd->driverPrivate)->enabled) - continue; - ephyrUpdateModifierState(ev.key_state); - KdEnqueueKeyboardEvent(ephyrKbd, ev.data.key_up.scancode, TRUE); + case XCB_MOTION_NOTIFY: + ephyrProcessMouseMotion(xev); break; -#ifdef XF86DRI - case EPHYR_EV_EXPOSE: - /* - * We only receive expose events when the expose event have - * be generated for a drawable that is a host X window managed - * by Xephyr. Host X windows managed by Xephyr exists for instance - * when Xephyr is asked to create a GL drawable in a DRI environment. - */ - ephyrExposePairedWindow(ev.data.expose.window); + case XCB_KEY_PRESS: + ephyrProcessKeyPress(xev); break; -#endif /* XF86DRI */ -#ifdef RANDR - case EPHYR_EV_CONFIGURE: - ephyrResizeScreen(screenInfo.screens[ev.data.configure.screen], - ev.data.configure.width, - ev.data.configure.height); + case XCB_KEY_RELEASE: + ephyrProcessKeyRelease(xev); + break; + + case XCB_BUTTON_PRESS: + ephyrProcessButtonPress(xev); + break; + + case XCB_BUTTON_RELEASE: + ephyrProcessButtonRelease(xev); break; -#endif /* RANDR */ - default: + case XCB_CONFIGURE_NOTIFY: + ephyrProcessConfigureNotify(xev); break; } + + free(xev); } } @@ -1091,7 +1285,7 @@ EphyrKeyboardInit(KdKeyboardInfo * ki) ki->driverPrivate = (EphyrKbdPrivate *) calloc(sizeof(EphyrKbdPrivate), 1); hostx_load_keymap(); - if (!ephyrKeySyms.map) { + if (!ephyrKeySyms.minKeyCode) { ErrorF("Couldn't load keymap from host\n"); return BadAlloc; } diff --git a/xorg-server/hw/kdrive/ephyr/ephyr.h b/xorg-server/hw/kdrive/ephyr/ephyr.h index be910c19e..73fdb59e6 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyr.h +++ b/xorg-server/hw/kdrive/ephyr/ephyr.h @@ -29,6 +29,7 @@ #include <unistd.h> #include <signal.h> #include <libgen.h> +#include <xcb/xcb_image.h> #include "os.h" /* for OsSignal() */ #include "kdrive.h" @@ -61,10 +62,24 @@ typedef struct _ephyrFakexaPriv { } 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; + int win_width, win_height; + int server_depth; + unsigned char *fb_data; /* only used when host bpp != server bpp */ + xcb_shm_segment_info_t shminfo; + + KdScreenInfo *screen; + int mynum; /* Screen number */ } EphyrScrPriv; extern KdCardFuncs ephyrFuncs; @@ -80,10 +95,7 @@ Bool ephyrCardInit(KdCardInfo * card); Bool - ephyrScreenInit(KdScreenInfo * screen); - -Bool - ephyrScreenInitialize(KdScreenInfo * screen, EphyrScrPriv * scrpriv); +ephyrScreenInitialize(KdScreenInfo *screen); Bool ephyrInitScreen(ScreenPtr pScreen); diff --git a/xorg-server/hw/kdrive/ephyr/ephyrdri.c b/xorg-server/hw/kdrive/ephyr/ephyrdri.c index 3a4a06301..16678fc5b 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrdri.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrdri.c @@ -29,10 +29,8 @@ #include <kdrive-config.h> #endif -#include <X11/Xutil.h> -#include <X11/Xlibint.h> -#include <GL/glx.h> -#include "xf86dri.h" +#include <X11/Xdefs.h> +#include <xcb/xf86dri.h> #include "hostx.h" #include "ephyrdri.h" #define _HAVE_XALLOC_DECLS @@ -49,13 +47,21 @@ Bool ephyrDRIQueryDirectRenderingCapable(int a_screen, Bool *a_is_capable) { - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); Bool is_ok = FALSE; + xcb_xf86dri_query_direct_rendering_capable_cookie_t cookie; + xcb_xf86dri_query_direct_rendering_capable_reply_t *reply; EPHYR_RETURN_VAL_IF_FAIL(a_is_capable, FALSE); EPHYR_LOG("enter\n"); - is_ok = XF86DRIQueryDirectRenderingCapable(dpy, DefaultScreen(dpy), - a_is_capable); + cookie = xcb_xf86dri_query_direct_rendering_capable(conn, + hostx_get_screen()); + reply = xcb_xf86dri_query_direct_rendering_capable_reply(conn, cookie, NULL); + if (reply) { + is_ok = TRUE; + *a_is_capable = reply->is_capable; + free(reply); + } EPHYR_LOG("leave. is_capable:%d, is_ok=%d\n", *a_is_capable, is_ok); return is_ok; @@ -65,31 +71,48 @@ Bool ephyrDRIOpenConnection(int a_screen, drm_handle_t * a_sarea, char **a_bus_id_string) { - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); Bool is_ok = FALSE; + xcb_xf86dri_open_connection_cookie_t cookie; + xcb_xf86dri_open_connection_reply_t *reply; EPHYR_RETURN_VAL_IF_FAIL(a_bus_id_string, FALSE); EPHYR_LOG("enter. screen:%d\n", a_screen); - is_ok = XF86DRIOpenConnection(dpy, DefaultScreen(dpy), - a_sarea, a_bus_id_string); - if (*a_bus_id_string) { - EPHYR_LOG("leave. bus_id_string:%s, is_ok:%d\n", - *a_bus_id_string, is_ok); - } - else { - EPHYR_LOG("leave. bus_id_string:null, is_ok:%d\n", is_ok); + cookie = xcb_xf86dri_open_connection(conn, hostx_get_screen()); + reply = xcb_xf86dri_open_connection_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_sarea = reply->sarea_handle_low; + if (sizeof(drm_handle_t) == 8) { + int shift = 32; + *a_sarea |= ((drm_handle_t) reply->sarea_handle_high) << shift; } + *a_bus_id_string = malloc(reply->bus_id_len + 1); + if (!*a_bus_id_string) + goto out; + memcpy(*a_bus_id_string, xcb_xf86dri_open_connection_bus_id(reply), reply->bus_id_len); + *a_bus_id_string[reply->bus_id_len] = '\0'; + is_ok = TRUE; +out: + free(reply); + EPHYR_LOG("leave. bus_id_string:%s, is_ok:%d\n", *a_bus_id_string, is_ok); return is_ok; } Bool ephyrDRIAuthConnection(int a_screen, drm_magic_t a_magic) { - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); + xcb_xf86dri_auth_connection_cookie_t cookie; + xcb_xf86dri_auth_connection_reply_t *reply; Bool is_ok = FALSE; EPHYR_LOG("enter\n"); - is_ok = XF86DRIAuthConnection(dpy, DefaultScreen(dpy), a_magic); + cookie = xcb_xf86dri_auth_connection(conn, screen, a_magic); + reply = xcb_xf86dri_auth_connection_reply(conn, cookie, NULL); + is_ok = reply->authenticated; + free(reply); EPHYR_LOG("leave. is_ok:%d\n", is_ok); return is_ok; } @@ -97,13 +120,13 @@ ephyrDRIAuthConnection(int a_screen, drm_magic_t a_magic) Bool ephyrDRICloseConnection(int a_screen) { - Display *dpy = hostx_get_display(); - Bool is_ok = FALSE; + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); EPHYR_LOG("enter\n"); - is_ok = XF86DRICloseConnection(dpy, DefaultScreen(dpy)); + xcb_xf86dri_close_connection(conn, screen); EPHYR_LOG("leave\n"); - return is_ok; + return TRUE; } Bool @@ -113,7 +136,10 @@ ephyrDRIGetClientDriverName(int a_screen, int *a_ddx_driver_patch_version, char **a_client_driver_name) { - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); + xcb_xf86dri_get_client_driver_name_cookie_t cookie; + xcb_xf86dri_get_client_driver_name_reply_t *reply; Bool is_ok = FALSE; EPHYR_RETURN_VAL_IF_FAIL(a_ddx_driver_major_version @@ -121,15 +147,27 @@ ephyrDRIGetClientDriverName(int a_screen, && a_ddx_driver_patch_version && a_client_driver_name, FALSE); EPHYR_LOG("enter\n"); - is_ok = XF86DRIGetClientDriverName(dpy, DefaultScreen(dpy), - a_ddx_driver_major_version, - a_ddx_driver_minor_version, - a_ddx_driver_patch_version, - a_client_driver_name); + cookie = xcb_xf86dri_get_client_driver_name(conn, screen); + reply = xcb_xf86dri_get_client_driver_name_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_ddx_driver_major_version = reply->client_driver_major_version; + *a_ddx_driver_minor_version = reply->client_driver_minor_version; + *a_ddx_driver_patch_version = reply->client_driver_patch_version; + *a_client_driver_name = malloc(reply->client_driver_name_len + 1); + if (!*a_client_driver_name) + goto out; + memcpy(*a_client_driver_name, + xcb_xf86dri_get_client_driver_name_client_driver_name(reply), + reply->client_driver_name_len); + (*a_client_driver_name)[reply->client_driver_name_len] = '\0'; + is_ok = TRUE; EPHYR_LOG("major:%d, minor:%d, patch:%d, name:%s\n", *a_ddx_driver_major_version, *a_ddx_driver_minor_version, *a_ddx_driver_patch_version, *a_client_driver_name); + out: + free(reply); EPHYR_LOG("leave:%d\n", is_ok); return is_ok; } @@ -139,17 +177,23 @@ ephyrDRICreateContext(int a_screen, int a_visual_id, CARD32 ctxt_id, drm_context_t * a_hw_ctxt) { - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); Bool is_ok = FALSE; - Visual v; - XID returned_ctxt_id = ctxt_id; + xcb_xf86dri_create_context_cookie_t cookie; + xcb_xf86dri_create_context_reply_t *reply; + + ctxt_id = xcb_generate_id(conn); EPHYR_LOG("enter. screen:%d, visual:%d\n", a_screen, a_visual_id); - memset(&v, 0, sizeof(v)); - v.visualid = a_visual_id; - is_ok = XF86DRICreateContext(dpy, - DefaultScreen(dpy), - &v, &returned_ctxt_id, a_hw_ctxt); + cookie = xcb_xf86dri_create_context(conn, screen, a_visual_id, ctxt_id); + reply = xcb_xf86dri_create_context_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_hw_ctxt = reply->hw_context; + is_ok = TRUE; +out: + free(reply); EPHYR_LOG("leave:%d\n", is_ok); return is_ok; } @@ -157,13 +201,13 @@ ephyrDRICreateContext(int a_screen, Bool ephyrDRIDestroyContext(int a_screen, int a_context_id) { - Display *dpy = hostx_get_display(); - Bool is_ok = FALSE; + xcb_connection_t *conn = hostx_get_xcbconn (); + int screen = hostx_get_screen(); EPHYR_LOG("enter\n"); - is_ok = XF86DRIDestroyContext(dpy, DefaultScreen(dpy), a_context_id); - EPHYR_LOG("leave:%d\n", is_ok); - return is_ok; + xcb_xf86dri_destroy_context(conn, screen, a_context_id); + EPHYR_LOG("leave\n"); + return TRUE; } Bool @@ -171,11 +215,20 @@ ephyrDRICreateDrawable(int a_screen, int a_drawable, drm_drawable_t * a_hw_drawable) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); + xcb_xf86dri_create_drawable_cookie_t cookie; + xcb_xf86dri_create_drawable_reply_t *reply; EPHYR_LOG("enter\n"); - is_ok = XF86DRICreateDrawable(dpy, DefaultScreen(dpy), - a_drawable, a_hw_drawable); + cookie = xcb_xf86dri_create_drawable(conn, screen, a_drawable); + reply = xcb_xf86dri_create_drawable_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_hw_drawable = reply->hw_drawable_handle; + is_ok = TRUE; +out: + free(reply); EPHYR_LOG("leave. is_ok:%d\n", is_ok); return is_ok; } @@ -206,7 +259,10 @@ ephyrDRIGetDrawableInfo(int a_screen, drm_clip_rect_t ** a_back_clip_rects) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); + xcb_xf86dri_get_drawable_info_cookie_t cookie; + xcb_xf86dri_get_drawable_info_reply_t *reply = NULL; EphyrHostWindowAttributes attrs; EPHYR_RETURN_VAL_IF_FAIL(a_x && a_y && a_w && a_h @@ -218,16 +274,22 @@ ephyrDRIGetDrawableInfo(int a_screen, EPHYR_LOG_ERROR("failed to query host window attributes\n"); goto out; } - if (!XF86DRIGetDrawableInfo(dpy, DefaultScreen(dpy), a_drawable, - a_index, a_stamp, - a_x, a_y, - a_w, a_h, - a_num_clip_rects, a_clip_rects, - a_back_x, a_back_y, - a_num_back_clip_rects, a_back_clip_rects)) { - EPHYR_LOG_ERROR("XF86DRIGetDrawableInfo ()\n"); + cookie = xcb_xf86dri_get_drawable_info(conn, screen, a_drawable); + reply = xcb_xf86dri_get_drawable_info_reply(conn, cookie, NULL); + if (!reply) { + EPHYR_LOG_ERROR ("XF86DRIGetDrawableInfo ()\n"); goto out; } + *a_index = reply->drawable_table_index; + *a_stamp = reply->drawable_table_stamp; + *a_x = reply->drawable_origin_X; + *a_y = reply->drawable_origin_Y; + *a_w = reply->drawable_size_W; + *a_h = reply->drawable_size_H; + *a_num_clip_rects = reply->num_clip_rects; + *a_clip_rects = calloc(*a_num_clip_rects, sizeof(drm_clip_rect_t)); + memcpy(*a_clip_rects, xcb_xf86dri_get_drawable_info_clip_rects(reply), + *a_num_clip_rects * sizeof(drm_clip_rect_t)); EPHYR_LOG("host x,y,w,h: (%d,%d,%d,%d)\n", *a_x, *a_y, *a_w, *a_h); if (*a_num_clip_rects) { free(*a_back_clip_rects); @@ -247,6 +309,7 @@ ephyrDRIGetDrawableInfo(int a_screen, out: EPHYR_LOG("leave. index:%d, stamp:%d, x,y:(%d,%d), w,y:(%d,%d)\n", *a_index, *a_stamp, *a_x, *a_y, *a_w, *a_h); + free(reply); return is_ok; } @@ -259,13 +322,35 @@ ephyrDRIGetDeviceInfo(int a_screen, int *a_dev_private_size, void **a_dev_private) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); + xcb_connection_t *conn = hostx_get_xcbconn (); + int screen = hostx_get_screen(); + xcb_xf86dri_get_device_info_cookie_t cookie; + xcb_xf86dri_get_device_info_reply_t *reply; - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); + EPHYR_RETURN_VAL_IF_FAIL(conn, FALSE); EPHYR_LOG("enter\n"); - is_ok = XF86DRIGetDeviceInfo(dpy, DefaultScreen(dpy), a_frame_buffer, - a_fb_origin, a_fb_size, a_fb_stride, - a_dev_private_size, a_dev_private); + cookie = xcb_xf86dri_get_device_info(conn, screen); + reply = xcb_xf86dri_get_device_info_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_frame_buffer = reply->framebuffer_handle_low; + if (sizeof(drm_handle_t) == 8) { + int shift = 32; + *a_frame_buffer |= ((drm_handle_t)reply->framebuffer_handle_high) << shift; + } + *a_fb_origin = reply->framebuffer_origin_offset; + *a_fb_size = reply->framebuffer_size; + *a_fb_stride = reply->framebuffer_stride; + *a_dev_private_size = reply->device_private_size; + *a_dev_private = calloc(reply->device_private_size, 1); + if (!*a_dev_private) + goto out; + memcpy(*a_dev_private, + xcb_xf86dri_get_device_info_device_private(reply), + reply->device_private_size); + is_ok = TRUE; +out: + free(reply); EPHYR_LOG("leave:%d\n", is_ok); return is_ok; } diff --git a/xorg-server/hw/kdrive/ephyr/ephyrdriext.c b/xorg-server/hw/kdrive/ephyr/ephyrdriext.c index 617ffb158..13df60a5b 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrdriext.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrdriext.c @@ -39,6 +39,9 @@ #define _XF86DRI_SERVER_ #include <X11/dri/xf86dri.h> #include <X11/dri/xf86driproto.h> +#include <xcb/xcb.h> +#include <xcb/shape.h> +#include <xcb/xf86dri.h> #include "misc.h" #include "privates.h" #include "dixstruct.h" @@ -1319,12 +1322,12 @@ ephyrDRIExtensionInit(ScreenPtr a_screen) EphyrDRIScreenPrivPtr screen_priv = NULL; EPHYR_LOG("enter\n"); - if (!hostx_has_dri()) { + if (!host_has_extension(&xcb_xf86dri_id)) { EPHYR_LOG("host does not have DRI extension\n"); goto out; } EPHYR_LOG("host X does have DRI extension\n"); - if (!hostx_has_xshape()) { + if (!host_has_extension(&xcb_shape_id)) { EPHYR_LOG("host does not have XShape extension\n"); goto out; } diff --git a/xorg-server/hw/kdrive/ephyr/ephyrglxext.c b/xorg-server/hw/kdrive/ephyr/ephyrglxext.c index 22d510891..632a9c474 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrglxext.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrglxext.c @@ -29,6 +29,7 @@ #include <kdrive-config.h> #endif +#include <xcb/glx.h> #include "extnsionst.h" #include "ephyrglxext.h" #include "ephyrhostglx.h" @@ -83,7 +84,7 @@ ephyrHijackGLXExtension(void) { const void *(*dispatch_functions)[2]; - if (!hostx_has_glx()) { + if (!host_has_extension(&xcb_glx_id)) { EPHYR_LOG("host X does not have GLX\n"); return FALSE; } @@ -380,10 +381,9 @@ ephyrGLXQueryServerString(__GLXclientState * a_cl, GLbyte * a_pc) int length = 0; EPHYR_LOG("enter\n"); - if (!ephyrHostGLXGetStringFromServer(req->screen, - req->name, - EPHYR_HOST_GLX_QueryServerString, - &server_string)) { + if (!ephyrHostGLXQueryServerString(req->screen, + req->name, + &server_string)) { EPHYR_LOG_ERROR("failed to query string from host\n"); goto out; } @@ -724,9 +724,7 @@ ephyrGLXGetStringReal(__GLXclientState * a_cl, GLbyte * a_pc, Bool a_do_swap) a_pc += __GLX_SINGLE_HDR_SIZE; name = *(GLenum *) (a_pc + 0); EPHYR_LOG("context_tag:%d, name:%d\n", context_tag, name); - if (!ephyrHostGLXGetStringFromServer(context_tag, - name, - EPHYR_HOST_GLX_GetString, &string)) { + if (!ephyrHostGLXGetString(context_tag, name, &string)) { EPHYR_LOG_ERROR("failed to get string from server\n"); goto out; } diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostglx.c b/xorg-server/hw/kdrive/ephyr/ephyrhostglx.c index 5ecb02d23..007524d04 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostglx.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrhostglx.c @@ -31,22 +31,10 @@ #include <kdrive-config.h> #endif -/* - * including some server headers (like kdrive-config.h) - * might define the macro _XSERVER64 - * on 64 bits machines. That macro must _NOT_ be defined for Xlib - * client code, otherwise bad things happen. - * So let's undef that macro if necessary. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - -#include <X11/Xlibint.h> -#include <GL/glx.h> -#include <GL/internal/glcore.h> +#include <X11/Xdefs.h> +#include <X11/Xmd.h> #include <GL/glxproto.h> -#include <GL/glxint.h> +#include <xcb/glx.h> #include "ephyrhostglx.h" #define _HAVE_XALLOC_DECLS #include "ephyrlog.h" @@ -62,41 +50,20 @@ enum VisualConfRequestType { static Bool ephyrHostGLXGetVisualConfigsInternal (enum VisualConfRequestType a_type, + xcb_glx_get_visual_configs_reply_t *reply, int32_t a_screen, - int32_t * a_num_visuals, - int32_t * a_num_props, int32_t * a_props_buf_size, int32_t ** a_props_buf); -Bool -ephyrHostGLXGetMajorOpcode(int *a_opcode) -{ - Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - static int opcode; - int first_event_return = 0, first_error_return = 0; - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - EPHYR_LOG("enter\n"); - if (!opcode) { - if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &opcode, - &first_event_return, &first_error_return)) { - EPHYR_LOG_ERROR("XQueryExtension() failed\n"); - goto out; - } - } - *a_opcode = opcode; - is_ok = TRUE; - out: - EPHYR_LOG("release\n"); - return is_ok; -} + int32_t *a_num_visuals, + int32_t *a_num_props, + int32_t *a_props_buf_size, + int32_t **a_props_buf); Bool ephyrHostGLXQueryVersion(int *a_major, int *a_minor) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int major_opcode = 0; - xGLXQueryVersionReq *req = NULL; - xGLXQueryVersionReply reply; + xcb_connection_t *conn = hostx_get_xcbconn(); + xcb_glx_query_version_cookie_t cookie; + xcb_glx_query_version_reply_t *reply; EPHYR_RETURN_VAL_IF_FAIL(a_major && a_minor, FALSE); EPHYR_LOG("enter\n"); @@ -107,26 +74,14 @@ ephyrHostGLXQueryVersion(int *a_major, int *a_minor) return TRUE; } - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); - goto out; - } - EPHYR_LOG("major opcode: %d\n", major_opcode); - /* Send the glXQueryVersion request */ - memset(&reply, 0, sizeof(reply)); - LockDisplay(dpy); - GetReq(GLXQueryVersion, req); - req->reqType = major_opcode; - req->glxCode = X_GLXQueryVersion; - req->majorVersion = 2; - req->minorVersion = 1; - _XReply(dpy, (xReply *) &reply, 0, False); - UnlockDisplay(dpy); - SyncHandle(); - - *a_major = glx_major = reply.majorVersion; - *a_minor = glx_minor = reply.minorVersion; + cookie = xcb_glx_query_version(conn, 2, 1); + reply = xcb_glx_query_version_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_major = reply->major_version; + *a_minor = reply->minor_version; + free(reply); EPHYR_LOG("major:%d, minor:%d\n", *a_major, *a_minor); @@ -136,129 +91,63 @@ ephyrHostGLXQueryVersion(int *a_major, int *a_minor) return is_ok; } -/** - * GLX protocol structure for the ficticious "GLXGenericGetString" request. - * - * This is a non-existant protocol packet. It just so happens that all of - * the real protocol packets used to request a string from the server have - * an identical binary layout. The only difference between them is the - * meaning of the \c for_whom field and the value of the \c glxCode. - * (this has been copied from the mesa source code) - */ -typedef struct GLXGenericGetString { - CARD8 reqType; - CARD8 glxCode; - CARD16 length B16; - CARD32 for_whom B32; - CARD32 name B32; -} xGLXGenericGetStringReq; - -/* These defines are only needed to make the GetReq macro happy. - */ -#define sz_xGLXGenericGetStringReq 12 -#define X_GLXGenericGetString 0 - Bool -ephyrHostGLXGetStringFromServer(int a_screen_number, - int a_string_name, - enum EphyrHostGLXGetStringOps a_op, - char **a_string) +ephyrHostGLXGetString(int a_context_tag, + int a_string_name, + char **a_string) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int default_screen = DefaultScreen(dpy); - xGLXGenericGetStringReq *req = NULL; - xGLXSingleReply reply; - unsigned long length = 0, numbytes = 0; - int major_opcode = 0, get_string_op = 0; + xcb_connection_t *conn = hostx_get_xcbconn(); + xcb_glx_get_string_cookie_t cookie; + xcb_glx_get_string_reply_t *reply; - EPHYR_RETURN_VAL_IF_FAIL(dpy && a_string, FALSE); + EPHYR_RETURN_VAL_IF_FAIL(conn && a_string, FALSE); EPHYR_LOG("enter\n"); - switch (a_op) { - case EPHYR_HOST_GLX_QueryServerString: - get_string_op = X_GLXQueryServerString; - break; - case EPHYR_HOST_GLX_GetString: - get_string_op = X_GLsop_GetString; - EPHYR_LOG("Going to glXGetString. strname:%#x, ctxttag:%d\n", - a_string_name, a_screen_number); - break; - default: - EPHYR_LOG_ERROR("unknown EphyrHostGLXGetStringOp:%d\n", a_op); + cookie = xcb_glx_get_string(conn, a_context_tag, a_string_name); + reply = xcb_glx_get_string_reply(conn, cookie, NULL); + if (!reply) goto out; - } - - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); - goto out; - } - EPHYR_LOG("major opcode: %d\n", major_opcode); - - LockDisplay(dpy); - - /* All of the GLX protocol requests for getting a string from the server - * look the same. The exact meaning of the a_for_whom field is usually - * either the screen number (for glXQueryServerString) or the context tag - * (for GLXSingle). - */ - GetReq(GLXGenericGetString, req); - req->reqType = major_opcode; - req->glxCode = get_string_op; - req->for_whom = default_screen; - req->name = a_string_name; - - _XReply(dpy, (xReply *) &reply, 0, False); - -#if UINT32_MAX >= (ULONG_MAX / 4) - if (reply.length >= (ULONG_MAX / 4)) { - _XEatDataWords(dpy, reply.length); - goto eat_out; - } -#endif - if (reply.length > 0) { - length = (unsigned long) reply.length * 4; - numbytes = reply.size; - if (numbytes > length) { - EPHYR_LOG_ERROR("string length %d longer than reply length %d\n", - numbytes, length); - goto eat_out; - } - } - EPHYR_LOG("going to get a string of size:%d\n", numbytes); - - if (numbytes < INT_MAX) - *a_string = Xcalloc(numbytes + 1, 1); - else - *a_string = NULL; - if (*a_string == NULL) { - EPHYR_LOG_ERROR("allocation failed\n"); - goto eat_out; - } + *a_string = malloc(reply->n + 1); + memcpy(*a_string, xcb_glx_get_string_string(reply), reply->n); + (*a_string)[reply->n] = '\0'; + free(reply); + is_ok = TRUE; +out: + EPHYR_LOG("leave\n"); + return is_ok; +} - if (_XRead(dpy, *a_string, numbytes)) { - EPHYR_LOG_ERROR("read failed\n"); - length = 0; /* if read failed, no idea how much to eat */ - } - else { - length -= numbytes; - EPHYR_LOG("strname:%#x, strvalue:'%s', strlen:%d\n", - a_string_name, *a_string, numbytes); - is_ok = TRUE; - } +Bool ephyrHostGLXQueryServerString(int a_screen_number, + int a_string_name, + char **a_string) +{ + Bool is_ok = FALSE; + xcb_connection_t *conn = hostx_get_xcbconn(); + int default_screen = hostx_get_screen(); + xcb_glx_query_server_string_cookie_t cookie; + xcb_glx_query_server_string_reply_t *reply; - eat_out: - _XEatData(dpy, length); - UnlockDisplay(dpy); - SyncHandle(); + EPHYR_RETURN_VAL_IF_FAIL(conn && a_string, FALSE); - out: + EPHYR_LOG("enter\n"); + cookie = xcb_glx_query_server_string(conn, default_screen, a_string_name); + reply = xcb_glx_query_server_string_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_string = malloc(reply->str_len + 1); + memcpy(*a_string, xcb_glx_query_server_string_string(reply), reply->str_len); + (*a_string)[reply->str_len] = '\0'; + free(reply); + is_ok = TRUE; +out: EPHYR_LOG("leave\n"); return is_ok; } static Bool ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type, + xcb_glx_get_visual_configs_reply_t *reply, int32_t a_screen, int32_t * a_num_visuals, int32_t * a_num_props, @@ -266,110 +155,36 @@ ephyrHostGLXGetVisualConfigsInternal(enum VisualConfRequestType a_type, int32_t ** a_props_buf) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - xGLXGetVisualConfigsReq *req; - xGLXGetFBConfigsReq *fb_req; - xGLXVendorPrivateWithReplyReq *vpreq; - xGLXGetFBConfigsSGIXReq *sgi_req; - xGLXGetVisualConfigsReply reply; - char *server_glx_version = NULL, *server_glx_extensions = NULL; - int j = 0, - major_opcode = 0, - num_props = 0, - num_visuals = 0, props_buf_size = 0, props_per_visual_size = 0; + int num_props = 0, num_visuals = 0, props_buf_size = 0; + int props_per_visual_size = 0; int32_t *props_buf = NULL; - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get opcode\n"); - goto out; - } - - LockDisplay(dpy); - switch (a_type) { - case EPHYR_GET_FB_CONFIG: - GetReq(GLXGetFBConfigs, fb_req); - fb_req->reqType = major_opcode; - fb_req->glxCode = X_GLXGetFBConfigs; - fb_req->screen = DefaultScreen(dpy); - break; - - case EPHYR_VENDOR_PRIV_GET_FB_CONFIG_SGIX: - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXGetFBConfigsSGIXReq - - sz_xGLXVendorPrivateWithReplyReq, vpreq); - sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; - sgi_req->reqType = major_opcode; - sgi_req->glxCode = X_GLXVendorPrivateWithReply; - sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; - sgi_req->screen = DefaultScreen(dpy); - break; - - case EPHYR_GET_VISUAL_CONFIGS: - GetReq(GLXGetVisualConfigs, req); - req->reqType = major_opcode; - req->glxCode = X_GLXGetVisualConfigs; - req->screen = DefaultScreen(dpy); - break; - } - - if (!_XReply(dpy, (xReply *) &reply, 0, False)) { - EPHYR_LOG_ERROR("unknown error\n"); - UnlockDisplay(dpy); - goto out; - } - if (!reply.numVisuals) { + if (!reply->num_visuals) { EPHYR_LOG_ERROR("screen does not support GL rendering\n"); - UnlockDisplay(dpy); - goto out; - } - num_visuals = reply.numVisuals; - - /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for - * FIXME: FBconfigs? - */ - /* Check number of properties */ - num_props = reply.numProps; - if ((num_props < __GLX_MIN_CONFIG_PROPS) || - (num_props > __GLX_MAX_CONFIG_PROPS)) { - /* Huh? Not in protocol defined limits. Punt */ - EPHYR_LOG_ERROR("got a bad reply to request\n"); - UnlockDisplay(dpy); goto out; } + num_visuals = reply->num_visuals; + + num_props = reply->num_properties; if (a_type != EPHYR_GET_VISUAL_CONFIGS) { num_props *= 2; } - props_per_visual_size = num_props * __GLX_SIZE_INT32; - props_buf_size = props_per_visual_size * reply.numVisuals; + props_per_visual_size = num_props * sizeof(uint32_t); + props_buf_size = props_per_visual_size * reply->num_visuals; props_buf = malloc(props_buf_size); - for (j = 0; j < reply.numVisuals; j++) { - if (_XRead(dpy, - &((char *) props_buf)[j * props_per_visual_size], - props_per_visual_size) != Success) { - EPHYR_LOG_ERROR("read failed\n"); - } - } - UnlockDisplay(dpy); + if (!props_buf) + goto out; + memcpy(props_buf, xcb_glx_get_visual_configs_property_list(reply), + props_buf_size); *a_num_visuals = num_visuals; - *a_num_props = reply.numProps; + *a_num_props = reply->num_properties; *a_props_buf_size = props_buf_size; *a_props_buf = props_buf; is_ok = TRUE; - out: - if (server_glx_version) { - XFree(server_glx_version); - server_glx_version = NULL; - } - if (server_glx_extensions) { - XFree(server_glx_extensions); - server_glx_extensions = NULL; - } - SyncHandle(); +out: return is_ok; } @@ -380,14 +195,27 @@ ephyrHostGLXGetVisualConfigs(int32_t a_screen, int32_t * a_props_buf_size, int32_t ** a_props_buf) { Bool is_ok = FALSE; + xcb_glx_get_visual_configs_cookie_t cookie; + xcb_glx_get_visual_configs_reply_t *reply; + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); EPHYR_LOG("enter\n"); - is_ok = ephyrHostGLXGetVisualConfigsInternal(EPHYR_GET_VISUAL_CONFIGS, - a_screen, - a_num_visuals, - a_num_props, - a_props_buf_size, a_props_buf); - + cookie = xcb_glx_get_visual_configs(conn, screen); + reply = xcb_glx_get_visual_configs_reply(conn, cookie, NULL); + if (!reply) + goto out; + is_ok = ephyrHostGLXGetVisualConfigsInternal + (EPHYR_GET_VISUAL_CONFIGS, + reply, + a_screen, + a_num_visuals, + a_num_props, + a_props_buf_size, + a_props_buf); + +out: + free(reply); EPHYR_LOG("leave:%d\n", is_ok); return is_ok; } @@ -399,12 +227,32 @@ ephyrHostGLXVendorPrivGetFBConfigsSGIX(int a_screen, int32_t * a_props_buf_size, int32_t ** a_props_buf) { - Bool is_ok = FALSE; + Bool is_ok=FALSE; + xcb_connection_t *conn = hostx_get_xcbconn(); + int screen = hostx_get_screen(); + xcb_glx_vendor_private_with_reply_cookie_t cookie; + union { + xcb_glx_vendor_private_with_reply_reply_t *vprep; + xcb_glx_get_visual_configs_reply_t *rep; + } reply; EPHYR_LOG("enter\n"); + cookie = xcb_glx_vendor_private_with_reply(conn, + X_GLXvop_GetFBConfigsSGIX, + 0, 4, (uint8_t *)&screen); + reply.vprep = xcb_glx_vendor_private_with_reply_reply(conn, cookie, NULL); + if (!reply.vprep) + goto out; is_ok = ephyrHostGLXGetVisualConfigsInternal (EPHYR_VENDOR_PRIV_GET_FB_CONFIG_SGIX, - a_screen, a_num_visuals, a_num_props, a_props_buf_size, a_props_buf); + reply.rep, + a_screen, + a_num_visuals, + a_num_props, + a_props_buf_size, + a_props_buf); +out: + free(reply.vprep); EPHYR_LOG("leave\n"); return is_ok; } @@ -413,39 +261,15 @@ Bool ephyrHostGLXSendClientInfo(int32_t a_major, int32_t a_minor, const char *a_extension_list) { - Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - xGLXClientInfoReq *req; + xcb_connection_t *conn = hostx_get_xcbconn(); int size; - int32_t major_opcode = 0; - - EPHYR_RETURN_VAL_IF_FAIL(dpy && a_extension_list, FALSE); - - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); - goto out; - } - - LockDisplay(dpy); - GetReq(GLXClientInfo, req); - req->reqType = major_opcode; - req->glxCode = X_GLXClientInfo; - req->major = a_major; - req->minor = a_minor; + EPHYR_RETURN_VAL_IF_FAIL(conn && a_extension_list, FALSE); - size = strlen(a_extension_list) + 1; - req->length += bytes_to_int32(size); - req->numbytes = size; - Data(dpy, a_extension_list, size); + size = strlen (a_extension_list) + 1; + xcb_glx_client_info(conn, a_major, a_minor, size, a_extension_list); - UnlockDisplay(dpy); - SyncHandle(); - - is_ok = TRUE; - - out: - return is_ok; + return TRUE; } Bool @@ -457,9 +281,9 @@ ephyrHostGLXCreateContext(int a_screen, Bool a_direct, int code) { + xcb_connection_t *conn = hostx_get_xcbconn(); Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int major_opcode = 0, remote_context_id = 0; + int remote_context_id = 0; EPHYR_LOG("enter. screen:%d, generic_id:%d, contextid:%d, rendertype:%d, " "direct:%d\n", a_screen, a_generic_id, a_context_id, @@ -471,39 +295,24 @@ ephyrHostGLXCreateContext(int a_screen, goto out; } - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); - goto out; - } - - LockDisplay(dpy); - switch (code) { case X_GLXCreateContext: { - /* Send the glXCreateContext request */ - xGLXCreateContextReq *req; - GetReq(GLXCreateContext, req); - req->reqType = major_opcode; - req->glxCode = X_GLXCreateContext; - req->context = remote_context_id; - req->visual = a_generic_id; - req->screen = DefaultScreen(dpy); - req->shareList = a_share_list_ctxt_id; - req->isDirect = a_direct; - } + xcb_glx_create_context(conn, + remote_context_id, + a_generic_id, + hostx_get_screen(), + a_share_list_ctxt_id, + a_direct); + } case X_GLXCreateNewContext: { - /* Send the glXCreateNewContext request */ - xGLXCreateNewContextReq *req; - GetReq(GLXCreateNewContext, req); - req->reqType = major_opcode; - req->glxCode = X_GLXCreateNewContext; - req->context = remote_context_id; - req->fbconfig = a_generic_id; - req->screen = DefaultScreen(dpy); - req->renderType = a_render_type; - req->shareList = a_share_list_ctxt_id; - req->isDirect = a_direct; + xcb_glx_create_new_context(conn, + remote_context_id, + a_generic_id, + hostx_get_screen(), + a_render_type, + a_share_list_ctxt_id, + a_direct); } default: @@ -511,9 +320,6 @@ ephyrHostGLXCreateContext(int a_screen, EPHYR_LOG("Internal error! Invalid CreateContext code!\n"); } - UnlockDisplay(dpy); - SyncHandle(); - is_ok = TRUE; out: @@ -524,30 +330,19 @@ ephyrHostGLXCreateContext(int a_screen, Bool ephyrHostDestroyContext(int a_ctxt_id) { + xcb_connection_t *conn = hostx_get_xcbconn(); Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int major_opcode = 0, remote_ctxt_id = 0; - xGLXDestroyContextReq *req = NULL; + int remote_ctxt_id = 0; EPHYR_LOG("enter:%d\n", a_ctxt_id); - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); - goto out; - } if (!hostx_get_resource_id_peer(a_ctxt_id, &remote_ctxt_id)) { EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n"); goto out; } EPHYR_LOG("host context id:%d\n", remote_ctxt_id); - LockDisplay(dpy); - GetReq(GLXDestroyContext, req); - req->reqType = major_opcode; - req->glxCode = X_GLXDestroyContext; - req->context = remote_ctxt_id; - UnlockDisplay(dpy); - SyncHandle(); + xcb_glx_destroy_context(conn, remote_ctxt_id); is_ok = TRUE; @@ -560,81 +355,71 @@ Bool ephyrHostGLXMakeCurrent(int a_drawable, int a_readable, int a_glx_ctxt_id, int a_old_ctxt_tag, int *a_ctxt_tag) { + xcb_connection_t *conn = hostx_get_xcbconn(); Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int32_t major_opcode = 0; int remote_glx_ctxt_id = 0; - xGLXMakeCurrentReply reply; EPHYR_RETURN_VAL_IF_FAIL(a_ctxt_tag, FALSE); EPHYR_LOG("enter. drawable:%d, read:%d, context:%d, oldtag:%d\n", a_drawable, a_readable, a_glx_ctxt_id, a_old_ctxt_tag); - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); - goto out; - } if (!hostx_get_resource_id_peer(a_glx_ctxt_id, &remote_glx_ctxt_id)) { EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n"); goto out; } - LockDisplay(dpy); - /* If both drawables are the same, use the old MakeCurrent request. * Otherwise, if we have GLX 1.3 or higher, use the MakeContextCurrent * request which supports separate read and draw targets. Failing that, * try the SGI MakeCurrentRead extension. Logic cribbed from Mesa. */ if (a_drawable == a_readable) { - xGLXMakeCurrentReq *req; - - GetReq(GLXMakeCurrent, req); - req->reqType = major_opcode; - req->glxCode = X_GLXMakeCurrent; - req->drawable = a_drawable; - req->context = remote_glx_ctxt_id; - req->oldContextTag = a_old_ctxt_tag; + xcb_glx_make_current_cookie_t cookie; + xcb_glx_make_current_reply_t *reply; + cookie = xcb_glx_make_current(conn, + a_drawable, + remote_glx_ctxt_id, + a_old_ctxt_tag); + reply = xcb_glx_make_current_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_ctxt_tag = reply->context_tag; + free(reply); } else if (glx_major > 1 || glx_minor >= 3) { - xGLXMakeContextCurrentReq *req; - - GetReq(GLXMakeContextCurrent, req); - req->reqType = major_opcode; - req->glxCode = X_GLXMakeContextCurrent; - req->drawable = a_drawable; - req->readdrawable = a_readable; - req->context = remote_glx_ctxt_id; - req->oldContextTag = a_old_ctxt_tag; + xcb_glx_make_context_current_cookie_t cookie; + xcb_glx_make_context_current_reply_t *reply; + cookie = xcb_glx_make_context_current(conn, + a_old_ctxt_tag, + a_drawable, + a_readable, + remote_glx_ctxt_id); + reply = xcb_glx_make_context_current_reply(conn, cookie, NULL); + if (!reply) + goto out; + *a_ctxt_tag = reply->context_tag; + free(reply); } else { - xGLXVendorPrivateWithReplyReq *vpreq; - xGLXMakeCurrentReadSGIReq *req; - - GetReqExtra(GLXVendorPrivateWithReply, - (sz_xGLXMakeCurrentReadSGIReq - - sz_xGLXVendorPrivateWithReplyReq), - vpreq); - req = (xGLXMakeCurrentReadSGIReq *) vpreq; - req->reqType = major_opcode; - req->glxCode = X_GLXVendorPrivateWithReply; - req->vendorCode = X_GLXvop_MakeCurrentReadSGI; - req->drawable = a_drawable; - req->readable = a_readable; - req->context = remote_glx_ctxt_id; - req->oldContextTag = a_old_ctxt_tag; - } + xcb_glx_vendor_private_with_reply_cookie_t cookie; + xcb_glx_vendor_private_with_reply_reply_t *reply; + uint32_t data[3] = { + a_drawable, a_readable, remote_glx_ctxt_id, + }; - memset(&reply, 0, sizeof(reply)); - if (!_XReply(dpy, (xReply *) &reply, 0, False)) { - EPHYR_LOG_ERROR("failed to get reply from host\n"); - UnlockDisplay(dpy); - SyncHandle(); - goto out; + EPHYR_LOG("enter\n"); + cookie = xcb_glx_vendor_private_with_reply(conn, + X_GLXvop_MakeCurrentReadSGI, + a_old_ctxt_tag, + sizeof(data), + (uint8_t *)data); + reply = xcb_glx_vendor_private_with_reply_reply(conn, cookie, NULL); + + *a_ctxt_tag = reply->retval; + + free(reply); } - UnlockDisplay(dpy); - SyncHandle(); - *a_ctxt_tag = reply.contextTag; + EPHYR_LOG("context tag:%d\n", *a_ctxt_tag); is_ok = TRUE; @@ -643,79 +428,32 @@ ephyrHostGLXMakeCurrent(int a_drawable, int a_readable, return is_ok; } -#define X_GLXSingle 0 - -#define __EPHYR_GLX_SINGLE_PUT_CHAR(offset,a) \ - *((INT8 *) (pc + offset)) = a - -#define EPHYR_GLX_SINGLE_PUT_SHORT(offset,a) \ - *((INT16 *) (pc + offset)) = a - -#define EPHYR_GLX_SINGLE_PUT_LONG(offset,a) \ - *((INT32 *) (pc + offset)) = a - -#define EPHYR_GLX_SINGLE_PUT_FLOAT(offset,a) \ - *((FLOAT32 *) (pc + offset)) = a - -#define EPHYR_GLX_SINGLE_READ_XREPLY() \ - (void) _XReply(dpy, (xReply*) &reply, 0, False) - -#define EPHYR_GLX_SINGLE_GET_RETVAL(a,cast) \ - a = (cast) reply.retval - -#define EPHYR_GLX_SINGLE_GET_SIZE(a) \ - a = (GLint) reply.size - -#define EPHYR_GLX_SINGLE_GET_CHAR(p) \ - *p = *(GLbyte *)&reply.pad3; - -#define EPHYR_GLX_SINGLE_GET_SHORT(p) \ - *p = *(GLshort *)&reply.pad3; - -#define EPHYR_GLX_SINGLE_GET_LONG(p) \ - *p = *(GLint *)&reply.pad3; - -#define EPHYR_GLX_SINGLE_GET_FLOAT(p) \ - *p = *(GLfloat *)&reply.pad3; - Bool ephyrHostGetIntegerValue(int a_current_context_tag, int a_int, int *a_val) { + xcb_connection_t *conn = hostx_get_xcbconn(); Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int major_opcode = 0, size = 0; - xGLXSingleReq *req = NULL; - xGLXSingleReply reply; - unsigned char *pc = NULL; + int size = 0; + xcb_glx_get_integerv_cookie_t cookie; + xcb_glx_get_integerv_reply_t *reply; EPHYR_RETURN_VAL_IF_FAIL(a_val, FALSE); EPHYR_LOG("enter\n"); - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); + cookie = xcb_glx_get_integerv(conn, a_current_context_tag, a_int); + reply = xcb_glx_get_integerv_reply(conn, cookie, NULL); + if (!reply) goto out; - } - LockDisplay(dpy); - GetReqExtra(GLXSingle, 4, req); - req->reqType = major_opcode; - req->glxCode = X_GLsop_GetIntegerv; - req->contextTag = a_current_context_tag; - pc = ((unsigned char *) (req) + sz_xGLXSingleReq); - EPHYR_GLX_SINGLE_PUT_LONG(0, a_int); - EPHYR_GLX_SINGLE_READ_XREPLY(); - EPHYR_GLX_SINGLE_GET_SIZE(size); + size = reply->n; if (!size) { - UnlockDisplay(dpy); - SyncHandle(); EPHYR_LOG_ERROR("X_GLsop_GetIngerv failed\n"); goto out; } - EPHYR_GLX_SINGLE_GET_LONG(a_val); - UnlockDisplay(dpy); - SyncHandle(); + *a_val = reply->datum; is_ok = TRUE; - out: +out: + free(reply); EPHYR_LOG("leave\n"); return is_ok; } @@ -724,40 +462,29 @@ Bool ephyrHostIsContextDirect(int a_ctxt_id, int *a_is_direct) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - xGLXIsDirectReq *req = NULL; - xGLXIsDirectReply reply; - int major_opcode = 0, remote_glx_ctxt_id = 0; + xcb_connection_t *conn = hostx_get_xcbconn(); + xcb_glx_is_direct_cookie_t cookie; + xcb_glx_is_direct_reply_t *reply = NULL; + int remote_glx_ctxt_id = 0; EPHYR_LOG("enter\n"); - if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) { - EPHYR_LOG_ERROR("failed to get major opcode\n"); + if (!hostx_get_resource_id_peer (a_ctxt_id, &remote_glx_ctxt_id)) { + EPHYR_LOG_ERROR ("failed to get remote glx ctxt id\n"); goto out; } - if (!hostx_get_resource_id_peer(a_ctxt_id, &remote_glx_ctxt_id)) { - EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n"); - goto out; - } - memset(&reply, 0, sizeof(reply)); /* Send the glXIsDirect request */ - LockDisplay(dpy); - GetReq(GLXIsDirect, req); - req->reqType = major_opcode; - req->glxCode = X_GLXIsDirect; - req->context = remote_glx_ctxt_id; - if (!_XReply(dpy, (xReply *) &reply, 0, False)) { + cookie = xcb_glx_is_direct(conn, remote_glx_ctxt_id); + reply = xcb_glx_is_direct_reply(conn, cookie, NULL); + if (!reply) { EPHYR_LOG_ERROR("fail in reading reply from host\n"); - UnlockDisplay(dpy); - SyncHandle(); goto out; } - UnlockDisplay(dpy); - SyncHandle(); - *a_is_direct = reply.isDirect; + *a_is_direct = reply->is_direct; is_ok = TRUE; - out: +out: + free(reply); EPHYR_LOG("leave\n"); return is_ok; } diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostglx.h b/xorg-server/hw/kdrive/ephyr/ephyrhostglx.h index 7ff515dc2..309d0f2f7 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostglx.h +++ b/xorg-server/hw/kdrive/ephyr/ephyrhostglx.h @@ -35,10 +35,12 @@ enum EphyrHostGLXGetStringOps { }; Bool ephyrHostGLXQueryVersion(int *a_maj, int *a_min); -Bool ephyrHostGLXGetStringFromServer(int a_screen_number, - int a_string_name, - enum EphyrHostGLXGetStringOps a_op, - char **a_string); +Bool ephyrHostGLXGetString(int a_context_tag, + int a_string_name, + char **a_string); +Bool ephyrHostGLXQueryServerString(int a_screen_number, + int a_string_name, + char **a_string); Bool ephyrHostGLXGetVisualConfigs(int a_screen, int32_t * a_num_visuals, int32_t * a_num_props, @@ -51,7 +53,6 @@ ephyrHostGLXVendorPrivGetFBConfigsSGIX(int a_screen, int32_t * a_num_props, int32_t * a_props_buf_size, int32_t ** a_props_buf); -Bool ephyrHostGLXGetMajorOpcode(int32_t * a_opcode); Bool ephyrHostGLXSendClientInfo(int32_t a_major, int32_t a_minor, const char *a_extension_list); Bool ephyrHostGLXCreateContext(int a_screen, diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostproxy.c b/xorg-server/hw/kdrive/ephyr/ephyrhostproxy.c deleted file mode 100644 index a4f25c159..000000000 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostproxy.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Xephyr - A kdrive X server thats runs in a host X window. - * Authored by Matthew Allum <mallum@openedhand.com> - * - * 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 <dodji@openedhand.com> - */ - -#ifdef HAVE_CONFIG_H -#include <kdrive-config.h> -#endif - -#include <X11/Xlibint.h> -#define _HAVE_XALLOC_DECLS -#include "ephyrlog.h" -#include "ephyrhostproxy.h" -#include "hostx.h" - -/* byte swap a short */ -#define swaps(x, n) { \ - n = ((char *) (x))[0];\ - ((char *) (x))[0] = ((char *) (x))[1];\ - ((char *) (x))[1] = n; } - -#define GetXReq(req) \ - WORD64ALIGN ;\ - if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (xReq *)(dpy->last_req = dpy->bufptr);\ - dpy->bufptr += SIZEOF(xReq);\ - dpy->request++ - -Bool -ephyrHostProxyDoForward(pointer a_request_buffer, - struct XReply *a_reply, Bool a_do_swap) -{ - Bool is_ok = FALSE; - int n = 0; - Display *dpy = hostx_get_display(); - xReq *in_req = (xReq *) a_request_buffer; - xReq *forward_req = NULL; - struct XReply reply; - - EPHYR_RETURN_VAL_IF_FAIL(in_req && dpy, FALSE); - - EPHYR_LOG("enter\n"); - - if (a_do_swap) { - swaps(&in_req->length); - } - EPHYR_LOG("Req {type:%d, data:%d, length:%d}\n", - in_req->reqType, in_req->data, in_req->length); - GetXReq(forward_req); - memmove(forward_req, in_req, 4); - - if (!_XReply(dpy, (xReply *) &reply, 0, FALSE)) { - EPHYR_LOG_ERROR("failed to get reply\n"); - goto out; - } - EPHYR_LOG("XReply{type:%d, foo:%d, seqnum:%d, length:%d}\n", - reply.type, reply.foo, reply.sequence_number, reply.length); - - if (a_reply) { - memmove(a_reply, &reply, sizeof(reply)); - } - is_ok = TRUE; - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostproxy.h b/xorg-server/hw/kdrive/ephyr/ephyrhostproxy.h deleted file mode 100644 index 13721606a..000000000 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostproxy.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Xephyr - A kdrive X server thats runs in a host X window. - * Authored by Matthew Allum <mallum@openedhand.com> - * - * 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 <dodji@openedhand.com> - */ - -#ifndef __EPHYRHOSTPROXY_H__ -#define __EPHYRHOSTPROXY_H__ - -struct XReply { - int8_t type; /*X_Reply */ - int8_t foo; - int16_t sequence_number; - int32_t length; - /*following is some data up to 32 bytes lenght */ - int32_t pad0; - int32_t pad1; - int32_t pad2; - int32_t pad3; - int32_t pad4; - int32_t pad5; -}; - -Bool - -ephyrHostProxyDoForward(pointer a_request_buffer, - struct XReply *a_reply, Bool a_do_swap); - -#endif /*__EPHYRHOSTPROXY_H__*/ diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c b/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c deleted file mode 100644 index 99f0f5071..000000000 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.c +++ /dev/null @@ -1,975 +0,0 @@ -/* - * Xephyr - A kdrive X server thats runs in a host X window. - * Authored by Matthew Allum <mallum@openedhand.com> - * - * 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 <dodji@openedhand.com> - */ -#ifdef HAVE_CONFIG_H -#include <kdrive-config.h> -#endif -/* - * including some server headers (like kdrive-config.h) - * might define the macro _XSERVER64 - * on 64 bits machines. That macro must _NOT_ be defined for Xlib - * client code, otherwise bad things happen. - * So let's undef that macro if necessary. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif -#include <X11/Xutil.h> -#include <X11/Xlibint.h> -#include <X11/extensions/Xvlib.h> -#include <X11/extensions/Xvproto.h> -#include <X11/extensions/Xext.h> -#include <X11/extensions/extutil.h> -#define _HAVE_XALLOC_DECLS - -#include "hostx.h" -#include "ephyrhostvideo.h" -#include "ephyrlog.h" - -#ifndef TRUE -#define TRUE 1 -#endif /*TRUE*/ -#ifndef FALSE -#define FALSE 0 -#endif /*FALSE*/ -static XExtensionInfo _xv_info_data; -static XExtensionInfo *xv_info = &_xv_info_data; -static const char *xv_extension_name = XvName; -static char *xv_error_string(Display * dpy, int code, XExtCodes * codes, - char *buf, int n); -static int xv_close_display(Display * dpy, XExtCodes * codes); -static Bool xv_wire_to_event(Display * dpy, XEvent * host, xEvent *wire); - -static XExtensionHooks xv_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - xv_close_display, /* close_display */ - xv_wire_to_event, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - xv_error_string /* error_string */ -}; - -static const char *xv_error_list[] = { - "BadPort", /* XvBadPort */ - "BadEncoding", /* XvBadEncoding */ - "BadControl" /* XvBadControl */ -}; - -#define XvCheckExtension(dpy, i, val) \ - XextCheckExtension(dpy, i, xv_extension_name, val) -#define XvGetReq(name, req) \ - WORD64ALIGN\ - if ((dpy->bufptr + SIZEOF(xv##name##Req)) > dpy->bufmax)\ - _XFlush(dpy);\ - req = (xv##name##Req *)(dpy->last_req = dpy->bufptr);\ - req->reqType = info->codes->major_opcode;\ - req->xvReqType = xv_##name; \ - req->length = (SIZEOF(xv##name##Req))>>2;\ - dpy->bufptr += SIZEOF(xv##name##Req);\ - dpy->request++ - -static -XEXT_GENERATE_CLOSE_DISPLAY(xv_close_display, xv_info) - -static -XEXT_GENERATE_FIND_DISPLAY(xv_find_display, xv_info, - xv_extension_name, - &xv_extension_hooks, XvNumEvents, NULL) - -static -XEXT_GENERATE_ERROR_STRING(xv_error_string, xv_extension_name, - XvNumErrors, xv_error_list) - -struct _EphyrHostXVAdaptorArray { - XvAdaptorInfo *adaptors; - unsigned int nb_adaptors; -}; - -/*heavily copied from libx11*/ -#define BUFSIZE 2048 -static void -ephyrHostXVLogXErrorEvent(Display * a_display, - XErrorEvent * a_err_event, FILE * a_fp) -{ - char buffer[BUFSIZ]; - char mesg[BUFSIZ]; - char number[32]; - const char *mtype = "XlibMessage"; - register _XExtension *ext = (_XExtension *) NULL; - _XExtension *bext = (_XExtension *) NULL; - Display *dpy = a_display; - - XGetErrorText(dpy, a_err_event->error_code, buffer, BUFSIZ); - XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); - (void) fprintf(a_fp, "%s: %s\n ", mesg, buffer); - XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", - mesg, BUFSIZ); - (void) fprintf(a_fp, mesg, a_err_event->request_code); - if (a_err_event->request_code < 128) { - snprintf(number, sizeof(number), "%d", a_err_event->request_code); - XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); - } - else { - for (ext = dpy->ext_procs; - ext && (ext->codes.major_opcode != a_err_event->request_code); - ext = ext->next); - if (ext) - strcpy(buffer, ext->name); - else - buffer[0] = '\0'; - } - (void) fprintf(a_fp, " (%s)\n", buffer); - if (a_err_event->request_code >= 128) { - XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", - mesg, BUFSIZ); - fputs(" ", a_fp); - (void) fprintf(a_fp, mesg, a_err_event->minor_code); - if (ext) { - snprintf(mesg, sizeof(mesg), "%s.%d", - ext->name, a_err_event->minor_code); - XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ); - (void) fprintf(a_fp, " (%s)", buffer); - } - fputs("\n", a_fp); - } - if (a_err_event->error_code >= 128) { - /* kludge, try to find the extension that caused it */ - buffer[0] = '\0'; - for (ext = dpy->ext_procs; ext; ext = ext->next) { - if (ext->error_string) - (*ext->error_string) (dpy, a_err_event->error_code, &ext->codes, - buffer, BUFSIZ); - if (buffer[0]) { - bext = ext; - break; - } - if (ext->codes.first_error && - ext->codes.first_error < (int) a_err_event->error_code && - (!bext || ext->codes.first_error > bext->codes.first_error)) - bext = ext; - } - if (bext) - snprintf(buffer, sizeof(buffer), "%s.%d", bext->name, - a_err_event->error_code - bext->codes.first_error); - else - strcpy(buffer, "Value"); - XGetErrorDatabaseText(dpy, mtype, buffer, "", mesg, BUFSIZ); - if (mesg[0]) { - fputs(" ", a_fp); - (void) fprintf(a_fp, mesg, a_err_event->resourceid); - fputs("\n", a_fp); - } - /* let extensions try to print the values */ - for (ext = dpy->ext_procs; ext; ext = ext->next) { - if (ext->error_values) - (*ext->error_values) (dpy, a_err_event, a_fp); - } - } - else if ((a_err_event->error_code == BadWindow) || - (a_err_event->error_code == BadPixmap) || - (a_err_event->error_code == BadCursor) || - (a_err_event->error_code == BadFont) || - (a_err_event->error_code == BadDrawable) || - (a_err_event->error_code == BadColor) || - (a_err_event->error_code == BadGC) || - (a_err_event->error_code == BadIDChoice) || - (a_err_event->error_code == BadValue) || - (a_err_event->error_code == BadAtom)) { - if (a_err_event->error_code == BadValue) - XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", - mesg, BUFSIZ); - else if (a_err_event->error_code == BadAtom) - XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", - mesg, BUFSIZ); - else - XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", - mesg, BUFSIZ); - fputs(" ", a_fp); - (void) fprintf(a_fp, mesg, a_err_event->resourceid); - fputs("\n", a_fp); - } - XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", - mesg, BUFSIZ); - fputs(" ", a_fp); - (void) fprintf(a_fp, mesg, a_err_event->serial); - XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d", - mesg, BUFSIZ); - fputs("\n ", a_fp); - (void) fprintf(a_fp, mesg, dpy->request); - fputs("\n", a_fp); -} - -static int -ephyrHostXVErrorHandler(Display * a_display, XErrorEvent * a_error_event) -{ - EPHYR_LOG_ERROR("got an error from the host xserver:\n"); - ephyrHostXVLogXErrorEvent(a_display, a_error_event, stderr); - return Success; -} - -void -ephyrHostXVInit(void) -{ - static Bool s_initialized; - - if (s_initialized) - return; - XSetErrorHandler(ephyrHostXVErrorHandler); - s_initialized = TRUE; -} - -Bool -ephyrHostXVQueryAdaptors(EphyrHostXVAdaptorArray ** a_adaptors) -{ - EphyrHostXVAdaptorArray *result = NULL; - int ret = 0; - Bool is_ok = FALSE; - - EPHYR_RETURN_VAL_IF_FAIL(a_adaptors, FALSE); - - EPHYR_LOG("enter\n"); - - result = calloc(1, sizeof(EphyrHostXVAdaptorArray)); - if (!result) - goto out; - - ret = XvQueryAdaptors(hostx_get_display(), - DefaultRootWindow(hostx_get_display()), - &result->nb_adaptors, &result->adaptors); - if (ret != Success) { - EPHYR_LOG_ERROR("failed to query host adaptors: %d\n", ret); - goto out; - } - *a_adaptors = result; - is_ok = TRUE; - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} - -void -ephyrHostXVAdaptorArrayDelete(EphyrHostXVAdaptorArray * a_adaptors) -{ - if (!a_adaptors) - return; - if (a_adaptors->adaptors) { - XvFreeAdaptorInfo(a_adaptors->adaptors); - a_adaptors->adaptors = NULL; - a_adaptors->nb_adaptors = 0; - } - XFree(a_adaptors); -} - -int -ephyrHostXVAdaptorArrayGetSize(const EphyrHostXVAdaptorArray * a_this) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this, -1); - return a_this->nb_adaptors; -} - -EphyrHostXVAdaptor * -ephyrHostXVAdaptorArrayAt(const EphyrHostXVAdaptorArray * a_this, int a_index) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL); - - if (a_index >= a_this->nb_adaptors) - return NULL; - return (EphyrHostXVAdaptor *) &a_this->adaptors[a_index]; -} - -char -ephyrHostXVAdaptorGetType(const EphyrHostXVAdaptor * a_this) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this, -1); - return ((const XvAdaptorInfo *) a_this)->type; -} - -const char * -ephyrHostXVAdaptorGetName(const EphyrHostXVAdaptor * a_this) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL); - - return ((const XvAdaptorInfo *) a_this)->name; -} - -EphyrHostVideoFormat * -ephyrHostXVAdaptorGetVideoFormats(const EphyrHostXVAdaptor * a_this, - int *a_nb_formats) -{ - EphyrHostVideoFormat *formats = NULL; - int nb_formats = 0, i = 0; - XVisualInfo *visual_info, visual_info_template; - int nb_visual_info; - - EPHYR_RETURN_VAL_IF_FAIL(a_this, NULL); - - nb_formats = ((const XvAdaptorInfo *) a_this)->num_formats; - formats = calloc(nb_formats, sizeof(EphyrHostVideoFormat)); - for (i = 0; i < nb_formats; i++) { - memset(&visual_info_template, 0, sizeof(visual_info_template)); - visual_info_template.visualid = - ((const XvAdaptorInfo *) a_this)->formats[i].visual_id; - visual_info = XGetVisualInfo(hostx_get_display(), - VisualIDMask, - &visual_info_template, &nb_visual_info); - formats[i].depth = ((const XvAdaptorInfo *) a_this)->formats[i].depth; - formats[i].visual_class = visual_info->class; - XFree(visual_info); - } - if (a_nb_formats) - *a_nb_formats = nb_formats; - return formats; -} - -int -ephyrHostXVAdaptorGetNbPorts(const EphyrHostXVAdaptor * a_this) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this, -1); - - return ((const XvAdaptorInfo *) a_this)->num_ports; -} - -int -ephyrHostXVAdaptorGetFirstPortID(const EphyrHostXVAdaptor * a_this) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this, -1); - - return ((const XvAdaptorInfo *) a_this)->base_id; -} - -Bool -ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE); - - if ((((const XvAdaptorInfo *) a_this)->type & - (XvVideoMask | XvInputMask)) == (XvVideoMask | XvInputMask)) - *a_result = TRUE; - else - *a_result = FALSE; - return TRUE; -} - -Bool -ephyrHostXVAdaptorHasGetVideo(const EphyrHostXVAdaptor * a_this, Bool *a_result) -{ - if ((((const XvAdaptorInfo *) a_this)->type & - (XvVideoMask | XvOutputMask)) == (XvVideoMask | XvOutputMask)) - *a_result = TRUE; - else - *a_result = FALSE; - return TRUE; -} - -Bool -ephyrHostXVAdaptorHasPutStill(const EphyrHostXVAdaptor * a_this, Bool *a_result) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE); - - if ((((const XvAdaptorInfo *) a_this)->type & - (XvStillMask | XvInputMask)) == (XvStillMask | XvInputMask)) - *a_result = TRUE; - else - *a_result = FALSE; - return TRUE; -} - -Bool -ephyrHostXVAdaptorHasGetStill(const EphyrHostXVAdaptor * a_this, Bool *a_result) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE); - - if ((((const XvAdaptorInfo *) a_this)->type & - (XvStillMask | XvOutputMask)) == (XvStillMask | XvOutputMask)) - *a_result = TRUE; - else - *a_result = FALSE; - return TRUE; -} - -Bool -ephyrHostXVAdaptorHasPutImage(const EphyrHostXVAdaptor * a_this, Bool *a_result) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_this && a_result, FALSE); - - if ((((const XvAdaptorInfo *) a_this)->type & - (XvImageMask | XvInputMask)) == (XvImageMask | XvInputMask)) - *a_result = TRUE; - else - *a_result = FALSE; - return TRUE; -} - -Bool -ephyrHostXVQueryEncodings(int a_port_id, - EphyrHostEncoding ** a_encodings, - unsigned int *a_num_encodings) -{ - EphyrHostEncoding *encodings = NULL; - XvEncodingInfo *encoding_info = NULL; - unsigned int num_encodings = 0, i; - int ret = 0; - - EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, FALSE); - - ret = XvQueryEncodings(hostx_get_display(), - a_port_id, &num_encodings, &encoding_info); - if (num_encodings && encoding_info) { - encodings = calloc(num_encodings, sizeof(EphyrHostEncoding)); - for (i = 0; i < num_encodings; i++) { - encodings[i].id = encoding_info[i].encoding_id; - encodings[i].name = strdup(encoding_info[i].name); - encodings[i].width = encoding_info[i].width; - encodings[i].height = encoding_info[i].height; - encodings[i].rate.numerator = encoding_info[i].rate.numerator; - encodings[i].rate.denominator = encoding_info[i].rate.denominator; - } - } - if (encoding_info) { - XvFreeEncodingInfo(encoding_info); - encoding_info = NULL; - } - *a_encodings = encodings; - *a_num_encodings = num_encodings; - - if (ret != Success) - return FALSE; - return TRUE; -} - -void -ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, int a_num_encodings) -{ - int i = 0; - - if (!a_encodings) - return; - for (i = 0; i < a_num_encodings; i++) { - free(a_encodings[i].name); - a_encodings[i].name = NULL; - } - free(a_encodings); -} - -void -ephyrHostAttributesDelete(EphyrHostAttribute * a_attributes) -{ - if (!a_attributes) - return; - XFree(a_attributes); -} - -Bool -ephyrHostXVQueryPortAttributes(int a_port_id, - EphyrHostAttribute ** a_attributes, - int *a_num_attributes) -{ - EPHYR_RETURN_VAL_IF_FAIL(a_attributes && a_num_attributes, FALSE); - - *a_attributes = - (EphyrHostAttribute *) XvQueryPortAttributes(hostx_get_display(), - a_port_id, - a_num_attributes); - - return TRUE; -} - -Bool -ephyrHostXVQueryImageFormats(int a_port_id, - EphyrHostImageFormat ** a_formats, - int *a_num_format) -{ - XvImageFormatValues *result = NULL; - - EPHYR_RETURN_VAL_IF_FAIL(a_formats && a_num_format, FALSE); - - result = XvListImageFormats(hostx_get_display(), a_port_id, a_num_format); - *a_formats = (EphyrHostImageFormat *) result; - return TRUE; - -} - -Bool -ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value) -{ - int res = Success; - - EPHYR_LOG("atom,name,value: (%d,%s,%d)\n", - a_atom, XGetAtomName(hostx_get_display(), a_atom), a_attr_value); - - res = XvSetPortAttribute(hostx_get_display(), - a_port_id, a_atom, a_attr_value); - if (res != Success) { - EPHYR_LOG_ERROR("XvSetPortAttribute() failed: %d\n", res); - return FALSE; - } - XFlush(hostx_get_display()); - EPHYR_LOG("leave\n"); - - return TRUE; -} - -Bool -ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value) -{ - int res = Success; - Bool ret = FALSE; - - EPHYR_RETURN_VAL_IF_FAIL(a_attr_value, FALSE); - - EPHYR_LOG("enter, a_port_id: %d, a_atomid: %d, attr_name: %s\n", - a_port_id, a_atom, XGetAtomName(hostx_get_display(), a_atom)); - - res = XvGetPortAttribute(hostx_get_display(), - a_port_id, a_atom, a_attr_value); - if (res != Success) { - EPHYR_LOG_ERROR("XvGetPortAttribute() failed: %d \n", res); - goto out; - } - EPHYR_LOG("atom,value: (%d, %d)\n", a_atom, *a_attr_value); - - ret = TRUE; - - out: - EPHYR_LOG("leave\n"); - return ret; -} - -Bool -ephyrHostXVQueryBestSize(int a_port_id, - Bool a_motion, - unsigned int a_frame_w, - unsigned int a_frame_h, - unsigned int a_drw_w, - unsigned int a_drw_h, - unsigned int *a_actual_w, unsigned int *a_actual_h) -{ - int res = 0; - Bool is_ok = FALSE; - - EPHYR_RETURN_VAL_IF_FAIL(a_actual_w && a_actual_h, FALSE); - - EPHYR_LOG("enter: frame (%dx%d), drw (%dx%d)\n", - a_frame_w, a_frame_h, a_drw_w, a_drw_h); - - res = XvQueryBestSize(hostx_get_display(), - a_port_id, - a_motion, - a_frame_w, a_frame_h, - a_drw_w, a_drw_h, a_actual_w, a_actual_h); - if (res != Success) { - EPHYR_LOG_ERROR("XvQueryBestSize() failed: %d\n", res); - goto out; - } - XSync(hostx_get_display(), FALSE); - - EPHYR_LOG("actual (%dx%d)\n", *a_actual_w, *a_actual_h); - is_ok = TRUE; - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} - -static Bool -xv_wire_to_event(Display * dpy, XEvent * host, xEvent *wire) -{ - XExtDisplayInfo *info = xv_find_display(dpy); - XvEvent *re = (XvEvent *) host; - xvEvent *event = (xvEvent *) wire; - - XvCheckExtension(dpy, info, False); - - switch ((event->u.u.type & 0x7F) - info->codes->first_event) { - case XvVideoNotify: - re->xvvideo.type = event->u.u.type & 0x7f; - re->xvvideo.serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); - re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0); - re->xvvideo.display = dpy; - re->xvvideo.time = event->u.videoNotify.time; - re->xvvideo.reason = event->u.videoNotify.reason; - re->xvvideo.drawable = event->u.videoNotify.drawable; - re->xvvideo.port_id = event->u.videoNotify.port; - break; - case XvPortNotify: - re->xvport.type = event->u.u.type & 0x7f; - re->xvport.serial = _XSetLastRequestRead(dpy, (xGenericReply *) event); - re->xvport.send_event = ((event->u.u.type & 0x80) != 0); - re->xvport.display = dpy; - re->xvport.time = event->u.portNotify.time; - re->xvport.port_id = event->u.portNotify.port; - re->xvport.attribute = event->u.portNotify.attribute; - re->xvport.value = event->u.portNotify.value; - break; - default: - return False; - } - - return True; -} - -Bool -ephyrHostXVQueryImageAttributes(int a_port_id, - int a_image_id /*image fourcc code */ , - unsigned short *a_width, - unsigned short *a_height, - int *a_image_size, - int *a_pitches, int *a_offsets) -{ - Display *dpy = hostx_get_display(); - Bool ret = FALSE; - XExtDisplayInfo *info = xv_find_display(dpy); - xvQueryImageAttributesReq *req = NULL; - xvQueryImageAttributesReply rep; - - EPHYR_RETURN_VAL_IF_FAIL(a_width, FALSE); - EPHYR_RETURN_VAL_IF_FAIL(a_height, FALSE); - EPHYR_RETURN_VAL_IF_FAIL(a_image_size, FALSE); - - XvCheckExtension(dpy, info, FALSE); - - LockDisplay(dpy); - - XvGetReq(QueryImageAttributes, req); - req->id = a_image_id; - req->port = a_port_id; - req->width = *a_width; - req->height = *a_height; - /* - * read the reply - */ - if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { - EPHYR_LOG_ERROR("QeryImageAttribute req failed\n"); - goto out; - } - if (a_pitches && a_offsets) { - _XRead(dpy, (char *) a_pitches, rep.num_planes << 2); - _XRead(dpy, (char *) a_offsets, rep.num_planes << 2); - } - else { - _XEatDataWords(dpy, rep.length); - } - *a_width = rep.width; - *a_height = rep.height; - *a_image_size = rep.data_size; - - ret = TRUE; - - out: - UnlockDisplay(dpy); - SyncHandle(); - return ret; -} - -Bool -ephyrHostGetAtom(const char *a_name, Bool a_create_if_not_exists, int *a_atom) -{ - int atom = None; - - EPHYR_RETURN_VAL_IF_FAIL(a_atom, FALSE); - - atom = XInternAtom(hostx_get_display(), a_name, a_create_if_not_exists); - if (atom == None) { - return FALSE; - } - *a_atom = atom; - return TRUE; -} - -char * -ephyrHostGetAtomName(int a_atom) -{ - return XGetAtomName(hostx_get_display(), a_atom); -} - -void -ephyrHostFree(void *a_pointer) -{ - if (a_pointer) - XFree(a_pointer); -} - -Bool -ephyrHostXVPutImage(int a_screen_num, - int a_port_id, - 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, - EphyrHostBox * a_clip_rects, int a_clip_rect_nums) -{ - Bool is_ok = TRUE; - XvImage *xv_image = NULL; - GC gc = 0; - XGCValues gc_values; - Display *dpy = hostx_get_display(); - XRectangle *rects = NULL; - int res = 0; - - EPHYR_RETURN_VAL_IF_FAIL(a_buf, FALSE); - - EPHYR_LOG("enter, num_clip_rects: %d\n", a_clip_rect_nums); - - memset(&gc_values, 0, sizeof(gc_values)); - gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values); - if (!gc) { - EPHYR_LOG_ERROR("failed to create gc \n"); - goto out; - } - xv_image = (XvImage *) XvCreateImage(hostx_get_display(), - a_port_id, a_image_id, - NULL, a_image_width, a_image_height); - if (!xv_image) { - EPHYR_LOG_ERROR("failed to create image\n"); - goto out; - } - xv_image->data = (char *) a_buf; - if (a_clip_rect_nums) { - int i = 0; - - rects = calloc(a_clip_rect_nums, sizeof(XRectangle)); - 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); - } - XSetClipRectangles(dpy, gc, 0, 0, rects, a_clip_rect_nums, YXBanded); - /*this always returns 1 */ - } - res = XvPutImage(dpy, a_port_id, - hostx_get_window(a_screen_num), - gc, xv_image, - a_src_x, a_src_y, a_src_w, a_src_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h); - if (res != Success) { - EPHYR_LOG_ERROR("XvPutImage() failed: %d\n", res); - goto out; - } - is_ok = TRUE; - - out: - if (xv_image) { - XFree(xv_image); - xv_image = NULL; - } - if (gc) { - XFreeGC(dpy, gc); - gc = NULL; - } - free(rects); - rects = NULL; - EPHYR_LOG("leave\n"); - return is_ok; -} - -Bool -ephyrHostXVPutVideo(int a_screen_num, int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) -{ - Bool is_ok = FALSE; - int res = FALSE; - GC gc = 0; - XGCValues gc_values; - Display *dpy = hostx_get_display(); - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - - gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values); - if (!gc) { - EPHYR_LOG_ERROR("failed to create gc \n"); - goto out; - } - res = XvPutVideo(dpy, a_port_id, hostx_get_window(a_screen_num), 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); - - if (res != Success) { - EPHYR_LOG_ERROR("XvPutVideo() failed: %d\n", res); - goto out; - } - - is_ok = TRUE; - - out: - if (gc) { - XFreeGC(dpy, gc); - gc = NULL; - } - return is_ok; -} - -Bool -ephyrHostXVGetVideo(int a_screen_num, int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) -{ - Bool is_ok = FALSE; - int res = FALSE; - GC gc = 0; - XGCValues gc_values; - Display *dpy = hostx_get_display(); - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - - gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values); - if (!gc) { - EPHYR_LOG_ERROR("failed to create gc \n"); - goto out; - } - res = XvGetVideo(dpy, a_port_id, hostx_get_window(a_screen_num), 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); - - if (res != Success) { - EPHYR_LOG_ERROR("XvGetVideo() failed: %d\n", res); - goto out; - } - - is_ok = TRUE; - - out: - if (gc) { - XFreeGC(dpy, gc); - gc = NULL; - } - return is_ok; -} - -Bool -ephyrHostXVPutStill(int a_screen_num, int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) -{ - Bool is_ok = FALSE; - int res = FALSE; - GC gc = 0; - XGCValues gc_values; - Display *dpy = hostx_get_display(); - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - - gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values); - if (!gc) { - EPHYR_LOG_ERROR("failed to create gc \n"); - goto out; - } - res = XvPutStill(dpy, a_port_id, hostx_get_window(a_screen_num), 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); - - if (res != Success) { - EPHYR_LOG_ERROR("XvPutStill() failed: %d\n", res); - goto out; - } - - is_ok = TRUE; - - out: - if (gc) { - XFreeGC(dpy, gc); - gc = NULL; - } - return is_ok; -} - -Bool -ephyrHostXVGetStill(int a_screen_num, int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h) -{ - Bool is_ok = FALSE; - int res = FALSE; - GC gc = 0; - XGCValues gc_values; - Display *dpy = hostx_get_display(); - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - - gc = XCreateGC(dpy, hostx_get_window(a_screen_num), 0L, &gc_values); - if (!gc) { - EPHYR_LOG_ERROR("failed to create gc \n"); - goto out; - } - res = XvGetStill(dpy, a_port_id, hostx_get_window(a_screen_num), 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); - - if (res != Success) { - EPHYR_LOG_ERROR("XvGetStill() failed: %d\n", res); - goto out; - } - - is_ok = TRUE; - - out: - if (gc) { - XFreeGC(dpy, gc); - gc = NULL; - } - return is_ok; -} - -Bool -ephyrHostXVStopVideo(int a_screen_num, int a_port_id) -{ - int ret = 0; - Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - - EPHYR_LOG("enter\n"); - - ret = XvStopVideo(dpy, a_port_id, hostx_get_window(a_screen_num)); - if (ret != Success) { - EPHYR_LOG_ERROR("XvStopVideo() failed: %d \n", ret); - goto out; - } - is_ok = TRUE; - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} diff --git a/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.h b/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.h deleted file mode 100644 index 0d3177277..000000000 --- a/xorg-server/hw/kdrive/ephyr/ephyrhostvideo.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Xephyr - A kdrive X server thats runs in a host X window. - * Authored by Matthew Allum <mallum@openedhand.com> - * - * 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 <dodji@openedhand.com> - */ -#ifndef __EPHYRHOSTVIDEO_H__ -#define __EPHYRHOSTVIDEO_H__ - -typedef void *EphyrHostXVAdaptor; -typedef struct _EphyrHostXVAdaptorArray EphyrHostXVAdaptorArray; - -typedef struct _EphyrHostVideoFormat { - char depth; - short visual_class; -} EphyrHostVideoFormat; - -typedef struct _EphyrHostRational { - int numerator; - int denominator; -} EphyrHostRational; - -typedef struct _EphyrHostEncoding { - int id; - char *name; - unsigned short width, height; - EphyrHostRational rate; -} EphyrHostEncoding; - -typedef struct _EphyrHostAttribute { - int flags; - int min_value; - int max_value; - char *name; -} EphyrHostAttribute; - -typedef struct _EphyrHostImageFormat { - int id; /* Unique descriptor for the format */ - int type; /* XvRGB, XvYUV */ - int byte_order; /* LSBFirst, MSBFirst */ - char guid[16]; /* Globally Unique IDentifier */ - int bits_per_pixel; - int format; /* XvPacked, XvPlanar */ - int num_planes; - - /* for RGB formats only */ - int depth; - unsigned int red_mask; - unsigned int green_mask; - unsigned int blue_mask; - - /* for YUV formats only */ - unsigned int y_sample_bits; - unsigned int u_sample_bits; - unsigned int v_sample_bits; - unsigned int horz_y_period; - unsigned int horz_u_period; - unsigned int horz_v_period; - unsigned int vert_y_period; - unsigned int vert_u_period; - unsigned int vert_v_period; - char component_order[32]; /* eg. UYVY */ - int scanline_order; /* XvTopToBottom, XvBottomToTop */ -} EphyrHostImageFormat; - -typedef struct { - unsigned short x1, y1, x2, y2; -} EphyrHostBox; - -void ephyrHostXVInit(void); - -void ephyrHostFree(void *a_pointer); - -/* - * host adaptor array - */ -Bool ephyrHostXVQueryAdaptors(EphyrHostXVAdaptorArray ** a_adaptors); -void ephyrHostXVAdaptorArrayDelete(EphyrHostXVAdaptorArray * a_adaptors); -int ephyrHostXVAdaptorArrayGetSize(const EphyrHostXVAdaptorArray * a_this); -EphyrHostXVAdaptor *ephyrHostXVAdaptorArrayAt(const EphyrHostXVAdaptorArray * - a_this, int a_index); - -/* - * host adaptor - */ - -char ephyrHostXVAdaptorGetType(const EphyrHostXVAdaptor * a_this); -const char *ephyrHostXVAdaptorGetName(const EphyrHostXVAdaptor * a_this); -EphyrHostVideoFormat *ephyrHostXVAdaptorGetVideoFormats - (const EphyrHostXVAdaptor * a_this, int *a_nb_formats); -int ephyrHostXVAdaptorGetNbPorts(const EphyrHostXVAdaptor * a_this); -int ephyrHostXVAdaptorGetFirstPortID(const EphyrHostXVAdaptor * a_this); - -Bool ephyrHostXVAdaptorHasPutVideo(const EphyrHostXVAdaptor * a_this, - Bool *a_result); -Bool ephyrHostXVAdaptorHasGetVideo(const EphyrHostXVAdaptor * a_this, - Bool *a_result); -Bool ephyrHostXVAdaptorHasPutStill(const EphyrHostXVAdaptor * a_this, - Bool *a_result); -Bool ephyrHostXVAdaptorHasGetStill(const EphyrHostXVAdaptor * a_this, - Bool *a_result); -Bool ephyrHostXVAdaptorHasPutImage(const EphyrHostXVAdaptor * a_this, - Bool *a_result); - -/* - * encoding - */ -Bool ephyrHostXVQueryEncodings(int a_port_id, - EphyrHostEncoding ** a_encodings, - unsigned int *a_num_encodings); - -void ephyrHostEncodingsDelete(EphyrHostEncoding * a_encodings, - int a_num_encodings); - -/* - * attribute - */ -Bool ephyrHostXVQueryPortAttributes(int a_port_id, - EphyrHostAttribute ** a_attributes, - int *a_num_attributes); - -void ephyrHostAttributesDelete(EphyrHostAttribute * a_attributes); - -/* - * image format - */ - -Bool ephyrHostXVQueryImageFormats(int a_port_id, - EphyrHostImageFormat ** a_formats, - int *a_num_format); -/* - * Port Attribute Get/Set - */ -Bool ephyrHostXVSetPortAttribute(int a_port_id, int a_atom, int a_attr_value); -Bool ephyrHostXVGetPortAttribute(int a_port_id, int a_atom, int *a_attr_value); - -/* - *size query - */ -Bool ephyrHostXVQueryBestSize(int a_port_id, - Bool a_motion, - unsigned int a_frame_w, - unsigned int a_frame_h, - unsigned int a_drw_w, - unsigned int a_drw_h, - unsigned int *a_actual_w, - unsigned int *a_actual_h); - -Bool ephyrHostXVQueryImageAttributes(int a_port_id, - int a_image_id /*image fourcc code */ , - unsigned short *a_width, - unsigned short *a_height, - int *a_image_size, - int *a_pitches, int *a_offsets); -/* - * atom - */ -Bool ephyrHostGetAtom(const char *a_name, - Bool a_create_if_not_exists, int *a_atom); -char *ephyrHostGetAtomName(int a_atom); - -/* - *PutImage - * (ignore clipping for now) - */ -Bool ephyrHostXVPutImage(int a_screen_num, - int a_port_id, - 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, - EphyrHostBox * a_clip_rects, int a_clip_rect_nums); - -/* - * Putvideo/PutStill/GetVideo - */ -Bool ephyrHostXVPutVideo(int a_screen_num, - int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h); - -Bool ephyrHostXVGetVideo(int a_screen_num, - int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h); - -Bool ephyrHostXVPutStill(int a_screen_num, - int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h); - -Bool ephyrHostXVGetStill(int a_screen_num, - int a_port_id, - int a_vid_x, int a_vid_y, int a_vid_w, int a_vid_h, - int a_drw_x, int a_drw_y, int a_drw_w, int a_drw_h); - -/* - * StopVideo - */ -Bool ephyrHostXVStopVideo(int a_screen_num, int a_port_id); - -#endif /*__EPHYRHOSTVIDEO_H__*/ diff --git a/xorg-server/hw/kdrive/ephyr/ephyrinit.c b/xorg-server/hw/kdrive/ephyr/ephyrinit.c index 9a1dd7d94..cf8bc9073 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrinit.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrinit.c @@ -28,6 +28,7 @@ #endif #include "ephyr.h" #include "ephyrlog.h" +#include "glx_extinit.h" extern Window EphyrPreExistingHostWin; extern Bool EphyrWantGrayScale; @@ -54,9 +55,28 @@ InitCard(char *name) KdCardInfoAdd(&ephyrFuncs, 0); } +static const ExtensionModule ephyrExtensions[] = { +#ifdef GLXEXT + { GlxExtensionInit, "GLX", &noGlxExtension }, +#endif +}; + +static +void ephyrExtensionInit(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ephyrExtensions); i++) + LoadExtension(&ephyrExtensions[i], TRUE); +} + + void InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv) { + if (serverGeneration == 1) + ephyrExtensionInit(); + KdInitOutput(pScreenInfo, argc, argv); } @@ -114,7 +134,7 @@ ddxUseMsg(void) ErrorF("\nXephyr Option Usage:\n"); ErrorF("-parent <XID> Use existing window as Xephyr root win\n"); - ErrorF("-host-cursor Re-use exisiting X host server cursor\n"); + ErrorF("-sw-cursor Render cursors in software in Xephyr\n"); ErrorF("-fullscreen Attempt to run Xephyr fullscreen\n"); ErrorF("-grayscale Simulate 8bit grayscale\n"); ErrorF("-resizeable Make Xephyr windows resizeable\n"); @@ -147,6 +167,9 @@ processScreenArg(const char *screen_size, char *parent_id) 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); @@ -200,8 +223,12 @@ ddxProcessArgument(int argc, char **argv, int i) UseMsg(); exit(1); } + else if (!strcmp(argv[i], "-sw-cursor")) { + hostx_use_sw_cursor(); + return 1; + } else if (!strcmp(argv[i], "-host-cursor")) { - hostx_use_host_cursor(); + /* Compatibility with the old command line argument, now the default. */ return 1; } else if (!strcmp(argv[i], "-fullscreen")) { @@ -369,7 +396,7 @@ ephyrCursorEnable(ScreenPtr pScreen) KdCardFuncs ephyrFuncs = { ephyrCardInit, /* cardinit */ - ephyrScreenInit, /* scrinit */ + ephyrScreenInitialize, /* scrinit */ ephyrInitScreen, /* initScreen */ ephyrFinishInitScreen, /* finishInitScreen */ ephyrCreateResources, /* createRes */ diff --git a/xorg-server/hw/kdrive/ephyr/ephyrproxyext.c b/xorg-server/hw/kdrive/ephyr/ephyrproxyext.c deleted file mode 100644 index c24238c04..000000000 --- a/xorg-server/hw/kdrive/ephyr/ephyrproxyext.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Xephyr - A kdrive X server thats runs in a host X window. - * Authored by Matthew Allum <mallum@openedhand.com> - * - * 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 <dodji@openedhand.com> - */ - -/* - * \file - * This file defines a proxy extension that forwards requests. - * When a request to extension FOO is sent to Xephyr, that request is forwared - * to the host X, without even trying to know what the request means. - */ - -#ifdef HAVE_CONFIG_H -#include <kdrive-config.h> -#endif - -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "ephyrproxyext.h" -#define _HAVE_XALLOC_DECLS -#include "ephyrlog.h" -#include "ephyrhostproxy.h" -#include "hostx.h" - -static Bool ephyrProxyGetHostExtensionInfo(const char *a_ext_name, - int *a_major_opcode, - int *a_first_event, - int *a_first_error); - -static int ephyrProxyProcDispatch(ClientPtr client); - -static Bool -ephyrProxyGetHostExtensionInfo(const char *a_ext_name, - int *a_major_opcode, - int *a_first_event, int *a_first_error) -{ - return hostx_get_extension_info(a_ext_name, a_major_opcode, - a_first_event, a_first_error); -} - -static int -ephyrProxyProcDispatch(ClientPtr a_client) -{ - int res = BadImplementation; - struct XReply reply; - - if (!ephyrHostProxyDoForward(a_client->requestBuffer, &reply, FALSE)) { - EPHYR_LOG_ERROR("forwarding failed\n"); - goto out; - } - reply.sequence_number = a_client->sequence; - res = Success; - - WriteToClient(a_client, 32, &reply); - - out: - return res; -} - -static void -ephyrProxyProcReset(ExtensionEntry * a_entry) -{ -} - -Bool -ephyrProxyExtensionInit(const char *a_extension_name) -{ - Bool is_ok = FALSE; - int major_opcode = 0, first_event = 0, first_error = 0; - ExtensionEntry *ext = NULL; - - if (!ephyrProxyGetHostExtensionInfo(a_extension_name, - &major_opcode, - &first_event, &first_error)) { - EPHYR_LOG("failed to query extension %s from host\n", a_extension_name); - goto out; - } - ext = AddExtension((char *) a_extension_name, 0, 0, - ephyrProxyProcDispatch, - ephyrProxyProcDispatch, - ephyrProxyProcReset, StandardMinorOpcode); - if (!ext) { - EPHYR_LOG_ERROR("failed to add the extension\n"); - goto out; - } - is_ok = TRUE; - - out: - EPHYR_LOG("leave\n"); - return is_ok; -} diff --git a/xorg-server/hw/kdrive/ephyr/ephyrproxyext.h b/xorg-server/hw/kdrive/ephyr/ephyrproxyext.h deleted file mode 100644 index 018b69b34..000000000 --- a/xorg-server/hw/kdrive/ephyr/ephyrproxyext.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Xephyr - A kdrive X server thats runs in a host X window. - * Authored by Matthew Allum <mallum@openedhand.com> - * - * 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 <dodji@openedhand.com> - */ -#ifndef __EPHYRPROXYEXT_H__ -#define __EPHYRPROXYEXT_H__ - -Bool ephyrProxyExtensionInit(const char *a_extension_name); - -#endif /*__EPHYRPROXYEXT_H__*/ diff --git a/xorg-server/hw/kdrive/ephyr/ephyrvideo.c b/xorg-server/hw/kdrive/ephyr/ephyrvideo.c index dfc29f533..4a05721af 100644 --- a/xorg-server/hw/kdrive/ephyr/ephyrvideo.c +++ b/xorg-server/hw/kdrive/ephyr/ephyrvideo.c @@ -31,15 +31,17 @@ #endif #include <string.h> #include <X11/extensions/Xv.h> +#include <xcb/xcb.h> +#include <xcb/xcb_aux.h> +#include <xcb/xv.h> #include "ephyrlog.h" #include "kdrive.h" #include "kxv.h" #include "ephyr.h" #include "hostx.h" -#include "ephyrhostvideo.h" struct _EphyrXVPriv { - EphyrHostXVAdaptorArray *host_adaptors; + xcb_xv_query_adaptors_reply_t *host_adaptors; KdVideoAdaptorPtr adaptors; int num_adaptors; }; @@ -58,14 +60,8 @@ struct _EphyrPortPriv { }; typedef struct _EphyrPortPriv EphyrPortPriv; -static Bool DoSimpleClip(BoxPtr a_dst_drw, BoxPtr a_clipper, BoxPtr a_result); - static Bool ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom); -/* -static Bool ephyrHostAtomToLocal (int a_host_atom, int *a_local_atom) ; -*/ - static EphyrXVPriv *ephyrXVPrivNew(void); static void ephyrXVPrivDelete(EphyrXVPriv * a_this); static Bool ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this); @@ -174,53 +170,18 @@ static int s_base_port_id; * ************/ static Bool -DoSimpleClip(BoxPtr a_dst_box, BoxPtr a_clipper, BoxPtr a_result) +adaptor_has_flags(const xcb_xv_adaptor_info_t *adaptor, uint32_t flags) { - BoxRec dstClippedBox; - - EPHYR_RETURN_VAL_IF_FAIL(a_dst_box && a_clipper && a_result, FALSE); - - /* - * setup the clipbox inside the destination. - */ - dstClippedBox.x1 = a_dst_box->x1; - dstClippedBox.x2 = a_dst_box->x2; - dstClippedBox.y1 = a_dst_box->y1; - dstClippedBox.y2 = a_dst_box->y2; - - /* - * if the cliper leftmost edge is inside - * the destination area then the leftmost edge of the resulting - * clipped box is the leftmost edge of the cliper. - */ - if (a_clipper->x1 > dstClippedBox.x1) - dstClippedBox.x1 = a_clipper->x1; - - /* - * if the cliper top edge is inside the destination area - * then the bottom horizontal edge of the resulting clipped box - * is the bottom edge of the cliper - */ - if (a_clipper->y1 > dstClippedBox.y1) - dstClippedBox.y1 = a_clipper->y1; - - /*ditto for right edge */ - if (a_clipper->x2 < dstClippedBox.x2) - dstClippedBox.x2 = a_clipper->x2; - - /*ditto for bottom edge */ - if (a_clipper->y2 < dstClippedBox.y2) - dstClippedBox.y2 = a_clipper->y2; - - memcpy(a_result, &dstClippedBox, sizeof(dstClippedBox)); - return TRUE; + 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; - int host_atom = None; EPHYR_RETURN_VAL_IF_FAIL(a_host_atom, FALSE); @@ -232,43 +193,18 @@ ephyrLocalAtomToHost(int a_local_atom, int *a_host_atom) if (!atom_name) return FALSE; - if (!ephyrHostGetAtom(atom_name, FALSE, &host_atom) || host_atom == None) { + 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 = host_atom; - return TRUE; -} - -/* - Not used yed. -static Bool -ephyrHostAtomToLocal (int a_host_atom, int *a_local_atom) -{ - Bool is_ok=FALSE ; - char *atom_name=NULL ; - int atom=None ; - - EPHYR_RETURN_VAL_IF_FAIL (a_local_atom, FALSE) ; - - atom_name = ephyrHostGetAtomName (a_host_atom) ; - if (!atom_name) - goto out ; - - atom = MakeAtom (atom_name, strlen (atom_name), TRUE) ; - if (atom == None) - goto out ; - *a_local_atom = atom ; - is_ok = TRUE ; + *a_host_atom = reply->atom; + free(reply); -out: - if (atom_name) { - ephyrHostFree (atom_name) ; - } - return is_ok ; + return TRUE; } -*/ /************** *</helpers> @@ -321,8 +257,6 @@ ephyrXVPrivNew(void) goto error; } - ephyrHostXVInit(); - if (!ephyrXVPrivQueryHostAdaptors(xv_priv)) { EPHYR_LOG_ERROR("failed to query the host x for xv properties\n"); goto error; @@ -351,7 +285,7 @@ ephyrXVPrivDelete(EphyrXVPriv * a_this) if (!a_this) return; if (a_this->host_adaptors) { - ephyrHostXVAdaptorArrayDelete(a_this->host_adaptors); + free(a_this->host_adaptors); a_this->host_adaptors = NULL; } free(a_this->adaptors); @@ -360,72 +294,174 @@ ephyrXVPrivDelete(EphyrXVPriv * a_this) EPHYR_LOG("leave\n"); } -static KdVideoEncodingPtr -videoEncodingDup(EphyrHostEncoding * a_encodings, int a_num_encodings) +static Bool +translate_video_encodings(KdVideoAdaptorPtr adaptor, + xcb_xv_adaptor_info_t *host_adaptor) { - KdVideoEncodingPtr result = NULL; - int i = 0; + 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]; - EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, NULL); + 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; - result = calloc(a_num_encodings, sizeof(KdVideoEncodingRec)); - for (i = 0; i < a_num_encodings; i++) { - result[i].id = a_encodings[i].id; - result[i].name = strdup(a_encodings[i].name); - result[i].width = a_encodings[i].width; - result[i].height = a_encodings[i].height; - result[i].rate.numerator = a_encodings[i].rate.numerator; - result[i].rate.denominator = a_encodings[i].rate.denominator; + xcb_xv_encoding_info_next(&encoding_it); } - return result; + + free(reply); + return TRUE; } -static KdAttributePtr -portAttributesDup(EphyrHostAttribute * a_encodings, int a_num_encodings) +static Bool +translate_xv_attributes(KdVideoAdaptorPtr adaptor, + xcb_xv_adaptor_info_t *host_adaptor) { + xcb_connection_t *conn = hostx_get_xcbconn(); int i = 0; - KdAttributePtr result = NULL; + 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); - EPHYR_RETURN_VAL_IF_FAIL(a_encodings && a_num_encodings, NULL); + if (!reply) + return FALSE; - result = calloc(a_num_encodings, sizeof(KdAttributeRec)); - if (!result) { + 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"); - return NULL; + free(reply); + return FALSE; } - for (i = 0; i < a_num_encodings; i++) { - result[i].flags = a_encodings[i].flags; - result[i].min_value = a_encodings[i].min_value; - result[i].max_value = a_encodings[i].max_value; - result[i].name = strdup(a_encodings[i].name); + + it = xcb_xv_query_port_attributes_attributes_iterator(reply); + for (i = 0; i < reply->num_attributes; i++) { + KdAttributePtr 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); } - return result; + + 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(KdImageRec)); + if (!adaptor->pImages) { + free(reply); + return FALSE; + } + + formats = xcb_xv_list_image_formats_format(reply); + for (i = 0; i < reply->num_formats; i++) { + KdImagePtr 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) { - EphyrHostXVAdaptor *cur_host_adaptor = NULL; - EphyrHostVideoFormat *video_formats = NULL; - EphyrHostEncoding *encodings = NULL; - EphyrHostAttribute *attributes = NULL; - EphyrHostImageFormat *image_formats = NULL; - int num_video_formats = 0, base_port_id = 0, - num_attributes = 0, num_formats = 0, i = 0, port_priv_offset = 0; - unsigned num_encodings = 0; + 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"); - if (!ephyrHostXVQueryAdaptors(&a_this->host_adaptors)) { - EPHYR_LOG_ERROR("failed to query host adaptors\n"); - goto out; + { + 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 = - ephyrHostXVAdaptorArrayGetSize(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; @@ -442,28 +478,28 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) 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; - cur_host_adaptor = ephyrHostXVAdaptorArrayAt(a_this->host_adaptors, i); - if (!cur_host_adaptor) - continue; - a_this->adaptors[i].nPorts = - ephyrHostXVAdaptorGetNbPorts(cur_host_adaptor); + 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 = ephyrHostXVAdaptorGetType(cur_host_adaptor); + 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; - if (ephyrHostXVAdaptorGetName(cur_host_adaptor)) - a_this->adaptors[i].name = - strdup(ephyrHostXVAdaptorGetName(cur_host_adaptor)); - else + 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 = ephyrHostXVAdaptorGetFirstPortID(cur_host_adaptor); + 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; @@ -471,24 +507,24 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) if (!s_base_port_id) s_base_port_id = base_port_id; - if (!ephyrHostXVQueryEncodings(base_port_id, - &encodings, &num_encodings)) { + 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].nEncodings = num_encodings; - a_this->adaptors[i].pEncodings = - videoEncodingDup(encodings, num_encodings); - video_formats = (EphyrHostVideoFormat *) - ephyrHostXVAdaptorGetVideoFormats(cur_host_adaptor, - &num_video_formats); - a_this->adaptors[i].pFormats = (KdVideoFormatPtr) video_formats; - a_this->adaptors[i].nFormats = num_video_formats; - /* got a_this->adaptors[i].nPorts already - a_this->adaptors[i].nPorts = - ephyrHostXVAdaptorGetNbPorts (cur_host_adaptor) ; - */ + + 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)); @@ -504,41 +540,26 @@ ephyrXVPrivQueryHostAdaptors(EphyrXVPriv * a_this) port_priv->xv_priv = a_this; a_this->adaptors[i].pPortPrivates[j].ptr = port_priv; } - if (!ephyrHostXVQueryPortAttributes(base_port_id, - &attributes, &num_attributes)) { + + 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; } - a_this->adaptors[i].pAttributes = - portAttributesDup(attributes, num_attributes); - a_this->adaptors[i].nAttributes = num_attributes; - /*make sure atoms of attrs names are created in xephyr */ - for (j = 0; j < a_this->adaptors[i].nAttributes; j++) { - if (a_this->adaptors[i].pAttributes[j].name) - MakeAtom(a_this->adaptors[i].pAttributes[j].name, - strlen(a_this->adaptors[i].pAttributes[j].name), TRUE); } - if (!ephyrHostXVQueryImageFormats(base_port_id, - &image_formats, &num_formats)) { + + 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; } - a_this->adaptors[i].pImages = (KdImagePtr) image_formats; - a_this->adaptors[i].nImages = num_formats; + + xcb_xv_adaptor_info_next(&it); } is_ok = TRUE; out: - if (encodings) { - ephyrHostEncodingsDelete(encodings, num_encodings); - encodings = NULL; - } - if (attributes) { - ephyrHostAttributesDelete(attributes); - attributes = NULL; - } EPHYR_LOG("leave\n"); return is_ok; } @@ -547,14 +568,16 @@ static Bool ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this) { int i = 0; - Bool has_it = FALSE; - EphyrHostXVAdaptor *cur_host_adaptor = NULL; + 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; @@ -562,50 +585,25 @@ ephyrXVPrivSetAdaptorsHooks(EphyrXVPriv * a_this) a_this->adaptors[i].QueryBestSize = ephyrQueryBestSize; a_this->adaptors[i].QueryImageAttributes = ephyrQueryImageAttributes; - cur_host_adaptor = ephyrHostXVAdaptorArrayAt(a_this->host_adaptors, i); - if (!cur_host_adaptor) { - EPHYR_LOG_ERROR("failed to get host adaptor at index %d\n", i); - continue; - } - has_it = FALSE; - if (!ephyrHostXVAdaptorHasPutImage(cur_host_adaptor, &has_it)) { - EPHYR_LOG_ERROR("error\n"); - } - if (has_it) { + if (adaptor_has_flags(cur_host_adaptor, + XCB_XV_TYPE_IMAGE_MASK | XCB_XV_TYPE_INPUT_MASK)) a_this->adaptors[i].PutImage = ephyrPutImage; - } - has_it = FALSE; - if (!ephyrHostXVAdaptorHasPutVideo(cur_host_adaptor, &has_it)) { - EPHYR_LOG_ERROR("error\n"); - } - if (has_it) { + if (adaptor_has_flags(cur_host_adaptor, + XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_INPUT_MASK)) a_this->adaptors[i].PutVideo = ephyrPutVideo; - } - has_it = FALSE; - if (!ephyrHostXVAdaptorHasGetVideo(cur_host_adaptor, &has_it)) { - EPHYR_LOG_ERROR("error\n"); - } - if (has_it) { + if (adaptor_has_flags(cur_host_adaptor, + XCB_XV_TYPE_VIDEO_MASK | XCB_XV_TYPE_OUTPUT_MASK)) a_this->adaptors[i].GetVideo = ephyrGetVideo; - } - has_it = FALSE; - if (!ephyrHostXVAdaptorHasPutStill(cur_host_adaptor, &has_it)) { - EPHYR_LOG_ERROR("error\n"); - } - if (has_it) { + if (adaptor_has_flags(cur_host_adaptor, + XCB_XV_TYPE_STILL_MASK | XCB_XV_TYPE_INPUT_MASK)) a_this->adaptors[i].PutStill = ephyrPutStill; - } - has_it = FALSE; - if (!ephyrHostXVAdaptorHasGetStill(cur_host_adaptor, &has_it)) { - EPHYR_LOG_ERROR("error\n"); - } - if (has_it) { + 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; @@ -691,20 +689,27 @@ ephyrXVPrivGetImageBufSize(int a_port_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; - unsigned short width = a_width, height = a_height; EPHYR_RETURN_VAL_IF_FAIL(a_size, FALSE); EPHYR_LOG("enter\n"); - if (!ephyrHostXVQueryImageAttributes(a_port_id, a_image_id, - &width, &height, a_size, NULL, NULL)) { - EPHYR_LOG_ERROR("failed to get image attributes\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; @@ -741,15 +746,14 @@ ephyrXVPrivSaveImageToPortPriv(EphyrPortPriv * a_port_priv, static void ephyrStopVideo(KdScreenInfo * a_info, pointer 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(a_info && a_info->pScreen); EPHYR_RETURN_IF_FAIL(port_priv); EPHYR_LOG("enter\n"); - if (!ephyrHostXVStopVideo(a_info->pScreen->myNum, port_priv->port_number)) { - EPHYR_LOG_ERROR("XvStopVideo() failed\n"); - } + xcb_xv_stop_video(conn, port_priv->port_number, scrpriv->win); EPHYR_LOG("leave\n"); } @@ -757,6 +761,7 @@ static int ephyrSetPortAttribute(KdScreenInfo * a_info, Atom a_attr_name, int a_attr_value, pointer 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; @@ -797,12 +802,9 @@ ephyrSetPortAttribute(KdScreenInfo * a_info, */ } - if (!ephyrHostXVSetPortAttribute(port_priv->port_number, - host_atom, a_attr_value)) { - EPHYR_LOG_ERROR("failed to set port attribute\n"); - 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: @@ -814,8 +816,12 @@ static int ephyrGetPortAttribute(KdScreenInfo * a_screen_info, Atom a_attr_name, int *a_attr_value, pointer 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); @@ -830,12 +836,17 @@ ephyrGetPortAttribute(KdScreenInfo * a_screen_info, goto out; } - if (!ephyrHostXVGetPortAttribute(port_priv->port_number, - host_atom, a_attr_value)) { - EPHYR_LOG_ERROR("failed to get port attribute\n"); + 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: @@ -853,21 +864,117 @@ ephyrQueryBestSize(KdScreenInfo * a_info, unsigned int *a_prefered_w, unsigned int *a_prefered_h, pointer a_port_priv) { - int res = 0; + 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_RETURN_IF_FAIL(port_priv); + EPHYR_LOG("leave\n"); +} - EPHYR_LOG("enter\n"); - res = ephyrHostXVQueryBestSize(port_priv->port_number, - a_motion, - a_src_w, a_src_h, - a_drw_w, a_drw_h, - a_prefered_w, a_prefered_h); - if (!res) { - EPHYR_LOG_ERROR("Failed to query best size\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 @@ -896,13 +1003,12 @@ ephyrPutImage(KdScreenInfo * a_info, EPHYR_LOG("enter\n"); - if (!ephyrHostXVPutImage(a_info->pScreen->myNum, - port_priv->port_number, + 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, - (EphyrHostBox *) RegionRects(a_clipping_region), + RegionRects(a_clipping_region), RegionNumRects(a_clipping_region))) { EPHYR_LOG_ERROR("EphyrHostXVPutImage() failed\n"); goto out; @@ -972,8 +1078,8 @@ ephyrReputImage(KdScreenInfo * a_info, EPHYR_LOG_ERROR("has null image buf in cache\n"); goto out; } - if (!ephyrHostXVPutImage(a_info->pScreen->myNum, - port_priv->port_number, + if (!ephyrHostXVPutImage(a_info, + port_priv, port_priv->image_id, a_drw_x, a_drw_y, port_priv->drw_w, port_priv->drw_h, @@ -981,7 +1087,7 @@ ephyrReputImage(KdScreenInfo * a_info, port_priv->src_w, port_priv->src_h, port_priv->image_width, port_priv->image_height, port_priv->image_buf, - (EphyrHostBox *) RegionRects(a_clipping_region), + RegionRects(a_clipping_region), RegionNumRects(a_clipping_region))) { EPHYR_LOG_ERROR("ephyrHostXVPutImage() failed\n"); goto out; @@ -1003,38 +1109,26 @@ ephyrPutVideo(KdScreenInfo * a_info, short a_drw_w, short a_drw_h, RegionPtr a_clipping_region, pointer 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; - BoxRec clipped_area, dst_box; - int result = BadImplementation; EPHYR_RETURN_VAL_IF_FAIL(a_info->pScreen, BadValue); EPHYR_RETURN_VAL_IF_FAIL(a_drawable && port_priv, BadValue); EPHYR_LOG("enter\n"); - dst_box.x1 = a_drw_x; - dst_box.x2 = a_drw_x + a_drw_w; - dst_box.y1 = a_drw_y; - dst_box.y2 = a_drw_y + a_drw_h; + 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); - if (!DoSimpleClip(&dst_box, - RegionExtents(a_clipping_region), &clipped_area)) { - EPHYR_LOG_ERROR("failed to simple clip\n"); - goto out; - } - - if (!ephyrHostXVPutVideo(a_info->pScreen->myNum, - port_priv->port_number, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h)) { - EPHYR_LOG_ERROR("ephyrHostXVPutVideo() failed\n"); - goto out; - } - result = Success; - - out: EPHYR_LOG("leave\n"); - return result; + return Success; } static int @@ -1046,38 +1140,27 @@ ephyrGetVideo(KdScreenInfo * a_info, short a_drw_w, short a_drw_h, RegionPtr a_clipping_region, pointer 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; - BoxRec clipped_area, dst_box; - int result = BadImplementation; 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"); - dst_box.x1 = a_drw_x; - dst_box.x2 = a_drw_x + a_drw_w; - dst_box.y1 = a_drw_y; - dst_box.y2 = a_drw_y + a_drw_h; - - if (!DoSimpleClip(&dst_box, - RegionExtents(a_clipping_region), &clipped_area)) { - EPHYR_LOG_ERROR("failed to simple clip\n"); - goto out; - } + 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); - if (!ephyrHostXVGetVideo(a_info->pScreen->myNum, - port_priv->port_number, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h)) { - EPHYR_LOG_ERROR("ephyrHostXVGetVideo() failed\n"); - goto out; - } - result = Success; + xcb_free_gc(conn, gc); - out: EPHYR_LOG("leave\n"); - return result; + return Success; } static int @@ -1089,38 +1172,26 @@ ephyrPutStill(KdScreenInfo * a_info, short a_drw_w, short a_drw_h, RegionPtr a_clipping_region, pointer 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; - BoxRec clipped_area, dst_box; - int result = BadImplementation; 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"); - dst_box.x1 = a_drw_x; - dst_box.x2 = a_drw_x + a_drw_w; - dst_box.y1 = a_drw_y; - dst_box.y2 = a_drw_y + a_drw_h; - - if (!DoSimpleClip(&dst_box, - RegionExtents(a_clipping_region), &clipped_area)) { - EPHYR_LOG_ERROR("failed to simple clip\n"); - goto out; - } + 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); - if (!ephyrHostXVPutStill(a_info->pScreen->myNum, - port_priv->port_number, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h)) { - EPHYR_LOG_ERROR("ephyrHostXVPutStill() failed\n"); - goto out; - } - result = Success; - - out: EPHYR_LOG("leave\n"); - return result; + return Success; } static int @@ -1132,38 +1203,26 @@ ephyrGetStill(KdScreenInfo * a_info, short a_drw_w, short a_drw_h, RegionPtr a_clipping_region, pointer 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; - BoxRec clipped_area, dst_box; - int result = BadImplementation; 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"); - dst_box.x1 = a_drw_x; - dst_box.x2 = a_drw_x + a_drw_w; - dst_box.y1 = a_drw_y; - dst_box.y2 = a_drw_y + a_drw_h; - - if (!DoSimpleClip(&dst_box, - RegionExtents(a_clipping_region), &clipped_area)) { - EPHYR_LOG_ERROR("failed to simple clip\n"); - goto out; - } + 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); - if (!ephyrHostXVGetStill(a_info->pScreen->myNum, - port_priv->port_number, - a_vid_x, a_vid_y, a_vid_w, a_vid_h, - a_drw_x, a_drw_y, a_drw_w, a_drw_h)) { - EPHYR_LOG_ERROR("ephyrHostXVGetStill() failed\n"); - goto out; - } - result = Success; - - out: EPHYR_LOG("leave\n"); - return result; + return Success; } static int @@ -1172,6 +1231,9 @@ ephyrQueryImageAttributes(KdScreenInfo * a_info, 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); @@ -1179,13 +1241,25 @@ ephyrQueryImageAttributes(KdScreenInfo * a_info, EPHYR_LOG("enter: dim (%dx%d), pitches: %p, offsets: %p\n", *a_w, *a_h, a_pitches, a_offsets); - if (!ephyrHostXVQueryImageAttributes(s_base_port_id, - a_id, - a_w, a_h, - &image_size, a_pitches, a_offsets)) { - EPHYR_LOG_ERROR("EphyrHostXVQueryImageAttributes() failed\n"); + 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: diff --git a/xorg-server/hw/kdrive/ephyr/hostx.c b/xorg-server/hw/kdrive/ephyr/hostx.c index 5071289d9..d98557147 100644 --- a/xorg-server/hw/kdrive/ephyr/hostx.c +++ b/xorg-server/hw/kdrive/ephyr/hostx.c @@ -27,17 +27,6 @@ #include <kdrive-config.h> #endif -/* - * including some server headers (like kdrive-config.h) - * might define the macro _XSERVER64 - * on 64 bits machines. That macro must _NOT_ be defined for Xlib - * client code, otherwise bad things happen. - * So let's undef that macro if necessary. - */ -#ifdef _XSERVER64 -#undef _XSERVER64 -#endif - #include "hostx.h" #include <stdlib.h> @@ -51,56 +40,36 @@ #include <sys/shm.h> #include <sys/time.h> -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/Xatom.h> #include <X11/keysym.h> -#include <X11/extensions/XShm.h> -#include <X11/extensions/shape.h> +#include <xcb/xcb.h> +#include <xcb/xproto.h> +#include <xcb/xcb_icccm.h> +#include <xcb/xcb_aux.h> +#include <xcb/shm.h> +#include <xcb/xcb_image.h> +#include <xcb/shape.h> +#include <xcb/xcb_keysyms.h> #ifdef XF86DRI -#include <GL/glx.h> -#endif /* XF86DRI */ +#include <xcb/xf86dri.h> +#include <xcb/glx.h> +#endif /* XF86DRI */ #include "ephyrlog.h" - -#ifdef XF86DRI -extern Bool XF86DRIQueryExtension(Display * dpy, - int *event_basep, int *error_basep); -#endif - -/* - * All xlib calls go here, which gets built as its own .a . - * Mixing kdrive and xlib headers causes all sorts of types - * to get clobbered. - */ - -struct EphyrHostScreen { - Window win; - Window win_pre_existing; /* Set via -parent option like xnest */ - Window peer_win; /* Used for GL; should be at most one */ - XImage *ximg; - int win_width, win_height; - int server_depth; - unsigned char *fb_data; /* only used when host bpp != server bpp */ - XShmSegmentInfo shminfo; - - void *info; /* Pointer to the screen this is associated with */ - int mynum; /* Screen number */ -}; +#include "ephyr.h" struct EphyrHostXVars { char *server_dpy_name; - Display *dpy; + xcb_connection_t *conn; int screen; - Visual *visual; + xcb_visualtype_t *visual; Window winroot; - GC gc; + xcb_gcontext_t gc; int depth; - Bool use_host_cursor; + Bool use_sw_cursor; Bool use_fullscreen; Bool have_shm; int n_screens; - struct EphyrHostScreen *screens; + KdScreenInfo **screens; long damage_debug_msec; @@ -126,57 +95,17 @@ char *ephyrTitle = NULL; static void hostx_set_fullscreen_hint(void); -/* X Error traps */ - -static int trapped_error_code = 0; -static int (*old_error_handler) (Display * d, XErrorEvent * e); - #define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth) -static struct EphyrHostScreen * -host_screen_from_screen_info(EphyrScreenInfo * screen) -{ - int i; - - for (i = 0; i < HostX.n_screens; i++) { - if (HostX.screens[i].info == screen) { - return &HostX.screens[i]; - } - } - return NULL; -} - -static int -error_handler(Display * display, XErrorEvent * error) -{ - trapped_error_code = error->error_code; - return 0; -} - -static void -hostx_errors_trap(void) -{ - trapped_error_code = 0; - old_error_handler = XSetErrorHandler(error_handler); -} - -static int -hostx_errors_untrap(void) -{ - XSetErrorHandler(old_error_handler); - return trapped_error_code; -} - int -hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height) +hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (host_screen && - (host_screen->win_pre_existing != None || - HostX.use_fullscreen == True)) { - *width = host_screen->win_width; - *height = host_screen->win_height; + if (scrpriv && (scrpriv->win_pre_existing != None || + HostX.use_fullscreen == TRUE)) { + *width = scrpriv->win_width; + *height = scrpriv->win_height; return 1; } @@ -184,17 +113,18 @@ hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height) } void -hostx_add_screen(EphyrScreenInfo screen, unsigned long win_id, int screen_num) +hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num) { + EphyrScrPriv *scrpriv = screen->driver; int index = HostX.n_screens; HostX.n_screens += 1; HostX.screens = realloc(HostX.screens, - HostX.n_screens * sizeof(struct EphyrHostScreen)); - memset(&HostX.screens[index], 0, sizeof(struct EphyrHostScreen)); + HostX.n_screens * sizeof(HostX.screens[0])); + HostX.screens[index] = screen; - HostX.screens[index].info = screen; - HostX.screens[index].win_pre_existing = win_id; + scrpriv->screen = screen; + scrpriv->win_pre_existing = win_id; } void @@ -204,58 +134,68 @@ hostx_set_display_name(char *name) } void -hostx_set_screen_number(EphyrScreenInfo screen, int number) +hostx_set_screen_number(KdScreenInfo *screen, int number) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (host_screen) { - host_screen->mynum = number; - hostx_set_win_title(host_screen->info, ""); + if (scrpriv) { + scrpriv->mynum = number; + hostx_set_win_title(screen, ""); } } void -hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text) +hostx_set_win_title(KdScreenInfo *screen, const char *extra_text) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (!host_screen) + if (!scrpriv) return; if (ephyrTitle) { - XStoreName(HostX.dpy, host_screen->win, ephyrTitle); - } - else { + 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, - host_screen->mynum, (extra_text != NULL) ? extra_text : ""); - - XStoreName(HostX.dpy, host_screen->win, buf); + 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_host_cursor; + return !HostX.use_sw_cursor; } void -hostx_use_host_cursor(void) +hostx_use_sw_cursor(void) { - HostX.use_host_cursor = True; + HostX.use_sw_cursor = TRUE; } int -hostx_want_preexisting_window(EphyrScreenInfo screen) +hostx_want_preexisting_window(KdScreenInfo *screen) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (host_screen && host_screen->win_pre_existing) { + if (scrpriv && scrpriv->win_pre_existing) { return 1; } else { @@ -266,7 +206,7 @@ hostx_want_preexisting_window(EphyrScreenInfo screen) void hostx_use_fullscreen(void) { - HostX.use_fullscreen = True; + HostX.use_fullscreen = TRUE; } int @@ -275,21 +215,35 @@ 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) { - Atom atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN; + xcb_atom_t atom_WINDOW_STATE, atom_WINDOW_STATE_FULLSCREEN; int index; + xcb_intern_atom_reply_t *reply; - atom_WINDOW_STATE = XInternAtom(HostX.dpy, "_NET_WM_STATE", False); - atom_WINDOW_STATE_FULLSCREEN - = XInternAtom(HostX.dpy, "_NET_WM_STATE_FULLSCREEN", False); + 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++) { - XChangeProperty(HostX.dpy, HostX.screens[index].win, - atom_WINDOW_STATE, XA_ATOM, 32, - PropModeReplace, - (unsigned char *) &atom_WINDOW_STATE_FULLSCREEN, 1); + 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); } } @@ -324,175 +278,220 @@ hostx_set_title(char *title) #pragma does_not_return(exit) #endif -static int _X_NORETURN -x_io_error_handler(Display * dpy) -{ - ErrorF("Lost connection to X server: %s\n", strerror(errno)); - CloseWellKnownConnections(); - OsCleanup(1); - exit(1); -} - int hostx_init(void) { - XSetWindowAttributes attr; - Cursor empty_cursor; - Pixmap cursor_pxm; - XColor col; + uint32_t attr; + xcb_cursor_t empty_cursor; + xcb_pixmap_t cursor_pxm; + uint16_t red, green, blue; + uint32_t pixel; int index; char *tmpstr; - XClassHint *class_hint; - - attr.event_mask = - ButtonPressMask - | ButtonReleaseMask - | PointerMotionMask - | KeyPressMask - | KeyReleaseMask - | ExposureMask - | StructureNotifyMask; + char *class_hint; + size_t class_len; + const xcb_query_extension_reply_t *shm_rep; + xcb_screen_t *xscreen; + + attr = + 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; EPHYR_DBG("mark"); - if ((HostX.dpy = XOpenDisplay(getenv("DISPLAY"))) == NULL) { + if ((HostX.conn = xcb_connect(NULL, &HostX.screen)) == NULL) { fprintf(stderr, "\nXephyr cannot open host display. Is DISPLAY set?\n"); exit(1); } - XSetIOErrorHandler(x_io_error_handler); - - HostX.screen = DefaultScreen(HostX.dpy); - HostX.winroot = RootWindow(HostX.dpy, HostX.screen); - HostX.gc = XCreateGC(HostX.dpy, HostX.winroot, 0, NULL); - HostX.depth = DefaultDepth(HostX.dpy, HostX.screen); - HostX.visual = DefaultVisual(HostX.dpy, HostX.screen); - - class_hint = XAllocClassHint(); + 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; + 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++) { - struct EphyrHostScreen *host_screen = &HostX.screens[index]; - - host_screen->server_depth = HostX.depth; - if (host_screen->win_pre_existing != None) { - Status result; - XWindowAttributes prewin_attr; + KdScreenInfo *screen = HostX.screens[index]; + EphyrScrPriv *scrpriv = screen->driver; - /* Get screen size from existing window */ - - hostx_errors_trap(); + scrpriv->win = xcb_generate_id(HostX.conn); + scrpriv->server_depth = HostX.depth; + scrpriv->ximg = NULL; - result = XGetWindowAttributes(HostX.dpy, - host_screen->win_pre_existing, - &prewin_attr); + 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; - if (hostx_errors_untrap() || !result) { - fprintf(stderr, "\nXephyr -parent window' does not exist!\n"); - exit(1); + /* 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); } - host_screen->win_width = prewin_attr.width; - host_screen->win_height = prewin_attr.height; - - host_screen->win = XCreateWindow(HostX.dpy, - host_screen->win_pre_existing, - 0, 0, - host_screen->win_width, - host_screen->win_height, - 0, - CopyFromParent, - CopyFromParent, - CopyFromParent, - CWEventMask, &attr); + 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, + XCB_COPY_FROM_PARENT, + XCB_CW_EVENT_MASK, + &attr); } else { - host_screen->win = XCreateWindow(HostX.dpy, HostX.winroot, 0, 0, 100, 100, /* will resize */ - 0, - CopyFromParent, - CopyFromParent, - CopyFromParent, - CWEventMask, &attr); - - hostx_set_win_title(host_screen->info, + 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, + XCB_COPY_FROM_PARENT, + XCB_CW_EVENT_MASK, + &attr); + + hostx_set_win_title(screen, "(ctrl+shift grabs mouse and keyboard)"); if (HostX.use_fullscreen) { - host_screen->win_width = DisplayWidth(HostX.dpy, HostX.screen); - host_screen->win_height = - DisplayHeight(HostX.dpy, HostX.screen); + scrpriv->win_width = xscreen->width_in_pixels; + scrpriv->win_height = xscreen->height_in_pixels; 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) { - tmpstr = getenv("RESOURCE_NAME"); - if (tmpstr && (!ephyrResNameFromCmd)) - ephyrResName = tmpstr; - class_hint->res_name = ephyrResName; - class_hint->res_class = "Xephyr"; - XSetClassHint(hostx_get_display(), host_screen->win, - 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 (class_hint) - XFree(class_hint); + if (!xcb_aux_parse_color("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); + } - XParseColor(HostX.dpy, DefaultColormap(HostX.dpy, HostX.screen), - "red", &col); - XAllocColor(HostX.dpy, DefaultColormap(HostX.dpy, HostX.screen), &col); - XSetForeground(HostX.dpy, HostX.gc, col.pixel); + xcb_change_gc(HostX.conn, HostX.gc, XCB_GC_FOREGROUND, &pixel); - if (!hostx_want_host_cursor()) { + if (!hostx_want_host_cursor ()) { /* Ditch the cursor, we provide our 'own' */ - cursor_pxm = XCreatePixmap(HostX.dpy, HostX.winroot, 1, 1, 1); - memset(&col, 0, sizeof(col)); - empty_cursor = XCreatePixmapCursor(HostX.dpy, - cursor_pxm, cursor_pxm, - &col, &col, 1, 1); + cursor_pxm = xcb_generate_id(HostX.conn); + xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1); + empty_cursor = xcb_generate_id(HostX.conn); + xcb_create_cursor(HostX.conn, + empty_cursor, + cursor_pxm, cursor_pxm, + 0,0,0, + 0,0,0, + 1,1); for (index = 0; index < HostX.n_screens; index++) { - XDefineCursor(HostX.dpy, HostX.screens[index].win, empty_cursor); + KdScreenInfo *screen = HostX.screens[index]; + EphyrScrPriv *scrpriv = screen->driver; + + xcb_change_window_attributes(HostX.conn, + scrpriv->win, + XCB_CW_CURSOR, + &empty_cursor); } - XFreePixmap(HostX.dpy, cursor_pxm); + xcb_free_pixmap(HostX.conn, cursor_pxm); } - for (index = 0; index < HostX.n_screens; index++) { - HostX.screens[index].ximg = NULL; - } /* Try to get share memory ximages for a little bit more speed */ - - if (!XShmQueryExtension(HostX.dpy) || getenv("XEPHYR_NO_SHM")) { + shm_rep = xcb_get_extension_data(HostX.conn, &xcb_shm_id); + if (!shm_rep || !shm_rep->present || getenv("XEPHYR_NO_SHM")) { fprintf(stderr, "\nXephyr unable to use SHM XImages\n"); - HostX.have_shm = False; + HostX.have_shm = FALSE; } else { - /* Really really check we have shm - better way ? */ - XShmSegmentInfo shminfo; + /* Really really check we have shm - better way ?*/ + xcb_shm_segment_info_t shminfo; + xcb_generic_error_t *e; + xcb_void_cookie_t cookie; + xcb_shm_seg_t shmseg; - HostX.have_shm = True; + HostX.have_shm = TRUE; - shminfo.shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT | 0777); - shminfo.shmaddr = shmat(shminfo.shmid, 0, 0); - shminfo.readOnly = True; + shminfo.shmid = shmget(IPC_PRIVATE, 1, IPC_CREAT|0777); + shminfo.shmaddr = shmat(shminfo.shmid,0,0); - hostx_errors_trap(); + shmseg = xcb_generate_id(HostX.conn); + cookie = xcb_shm_attach_checked(HostX.conn, shmseg, shminfo.shmid, + TRUE); + e = xcb_request_check(HostX.conn, cookie); - XShmAttach(HostX.dpy, &shminfo); - XSync(HostX.dpy, False); - - if (hostx_errors_untrap()) { + if (e) { fprintf(stderr, "\nXephyr unable to use SHM XImages\n"); - HostX.have_shm = False; + HostX.have_shm = FALSE; + free(e); } shmdt(shminfo.shmaddr); shmctl(shminfo.shmid, IPC_RMID, 0); } - XFlush(HostX.dpy); + xcb_flush(HostX.conn); /* Setup the pause time between paints when debugging updates */ @@ -513,51 +512,42 @@ hostx_get_depth(void) } int -hostx_get_server_depth(EphyrScreenInfo screen) -{ - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); - - return host_screen ? host_screen->server_depth : 0; -} - -void -hostx_set_server_depth(EphyrScreenInfo screen, int depth) +hostx_get_server_depth(KdScreenInfo *screen) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (host_screen) - host_screen->server_depth = depth; + return scrpriv ? scrpriv->server_depth : 0; } int -hostx_get_bpp(EphyrScreenInfo screen) +hostx_get_bpp(KdScreenInfo *screen) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (!host_screen) + if (!scrpriv) return 0; - if (host_depth_matches_server(host_screen)) - return HostX.visual->bits_per_rgb; + if (host_depth_matches_server(scrpriv)) + return HostX.visual->bits_per_rgb_value; else - return host_screen->server_depth; /*XXX correct ? */ + return scrpriv->server_depth; /*XXX correct ?*/ } void -hostx_get_visual_masks(EphyrScreenInfo screen, +hostx_get_visual_masks(KdScreenInfo *screen, CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - if (!host_screen) + if (!scrpriv) return; - if (host_depth_matches_server(host_screen)) { + if (host_depth_matches_server(scrpriv)) { *rmsk = HostX.visual->red_mask; *gmsk = HostX.visual->green_mask; *bmsk = HostX.visual->blue_mask; } - else if (host_screen->server_depth == 16) { + else if (scrpriv->server_depth == 16) { /* Assume 16bpp 565 */ *rmsk = 0xf800; *gmsk = 0x07e0; @@ -618,17 +608,14 @@ hostx_set_cmap_entry(unsigned char idx, * by fakexa for storing offscreen pixmap data. */ void * -hostx_screen_init(EphyrScreenInfo screen, +hostx_screen_init(KdScreenInfo *screen, int width, int height, int buffer_height, int *bytes_per_line, int *bits_per_pixel) { - int bitmap_pad; - Bool shm_success = False; - XSizeHints *size_hints; + EphyrScrPriv *scrpriv = screen->driver; + Bool shm_success = FALSE; - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); - - if (!host_screen) { + if (!scrpriv) { fprintf(stderr, "%s: Error in accessing hostx data\n", __func__); exit(1); } @@ -636,111 +623,119 @@ hostx_screen_init(EphyrScreenInfo screen, EPHYR_DBG("host_screen=%p wxh=%dx%d, buffer_height=%d", host_screen, width, height, buffer_height); - if (host_screen->ximg != NULL) { + if (scrpriv->ximg != NULL) { /* Free up the image data if previously used * i.ie called by server reset */ if (HostX.have_shm) { - XShmDetach(HostX.dpy, &host_screen->shminfo); - XDestroyImage(host_screen->ximg); - shmdt(host_screen->shminfo.shmaddr); - shmctl(host_screen->shminfo.shmid, IPC_RMID, 0); + xcb_shm_detach(HostX.conn, scrpriv->shminfo.shmseg); + xcb_image_destroy(scrpriv->ximg); + shmdt(scrpriv->shminfo.shmaddr); + shmctl(scrpriv->shminfo.shmid, IPC_RMID, 0); } else { - free(host_screen->ximg->data); - host_screen->ximg->data = NULL; + free(scrpriv->ximg->data); + scrpriv->ximg->data = NULL; - XDestroyImage(host_screen->ximg); + xcb_image_destroy(scrpriv->ximg); } } if (HostX.have_shm) { - host_screen->ximg = - XShmCreateImage(HostX.dpy, HostX.visual, HostX.depth, ZPixmap, NULL, - &host_screen->shminfo, width, buffer_height); - - host_screen->shminfo.shmid = + scrpriv->ximg = xcb_image_create_native(HostX.conn, + width, + buffer_height, + XCB_IMAGE_FORMAT_Z_PIXMAP, + HostX.depth, + NULL, + ~0, + NULL); + + scrpriv->shminfo.shmid = shmget(IPC_PRIVATE, - host_screen->ximg->bytes_per_line * buffer_height, + scrpriv->ximg->stride * buffer_height, IPC_CREAT | 0777); - host_screen->ximg->data = shmat(host_screen->shminfo.shmid, 0, 0); - host_screen->shminfo.shmaddr = host_screen->ximg->data; + scrpriv->ximg->data = shmat(scrpriv->shminfo.shmid, 0, 0); + scrpriv->shminfo.shmaddr = scrpriv->ximg->data; - if (host_screen->ximg->data == (char *) -1) { + if (scrpriv->ximg->data == (uint8_t *) -1) { EPHYR_DBG ("Can't attach SHM Segment, falling back to plain XImages"); - HostX.have_shm = False; - XDestroyImage(host_screen->ximg); - shmctl(host_screen->shminfo.shmid, IPC_RMID, 0); + HostX.have_shm = FALSE; + xcb_image_destroy (scrpriv->ximg); + shmctl(scrpriv->shminfo.shmid, IPC_RMID, 0); } else { - EPHYR_DBG("SHM segment attached %p", host_screen->shminfo.shmaddr); - host_screen->shminfo.readOnly = False; - XShmAttach(HostX.dpy, &host_screen->shminfo); - shm_success = True; + EPHYR_DBG("SHM segment attached %p", scrpriv->shminfo.shmaddr); + scrpriv->shminfo.shmseg = xcb_generate_id(HostX.conn); + xcb_shm_attach(HostX.conn, + scrpriv->shminfo.shmseg, + scrpriv->shminfo.shmid, + FALSE); + shm_success = TRUE; } } if (!shm_success) { - bitmap_pad = (HostX.depth > 16) ? 32 : ((HostX.depth > 8) ? 16 : 8); - - EPHYR_DBG("Creating image %dx%d for screen host_screen=%p\n", - width, buffer_height, host_screen); - host_screen->ximg = XCreateImage(HostX.dpy, - HostX.visual, - HostX.depth, - ZPixmap, 0, 0, - width, buffer_height, bitmap_pad, 0); - - host_screen->ximg->data = - malloc(host_screen->ximg->bytes_per_line * buffer_height); + 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); + + scrpriv->ximg->data = + malloc(scrpriv->ximg->stride * buffer_height); } - *bytes_per_line = host_screen->ximg->bytes_per_line; - *bits_per_pixel = host_screen->ximg->bits_per_pixel; - - XResizeWindow(HostX.dpy, host_screen->win, width, height); - - /* Ask the WM to keep our size static */ - if (host_screen->win_pre_existing == None && !EphyrWantResize) { - size_hints = XAllocSizeHints(); - size_hints->max_width = size_hints->min_width = width; - size_hints->max_height = size_hints->min_height = height; - size_hints->flags = PMinSize | PMaxSize; - XSetWMNormalHints(HostX.dpy, host_screen->win, size_hints); - XFree(size_hints); + *bytes_per_line = scrpriv->ximg->stride; + *bits_per_pixel = scrpriv->ximg->bpp; + + 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); } - XMapWindow(HostX.dpy, host_screen->win); + xcb_map_window(HostX.conn, scrpriv->win); - XSync(HostX.dpy, False); + xcb_aux_sync(HostX.conn); - host_screen->win_width = width; - host_screen->win_height = height; + scrpriv->win_width = width; + scrpriv->win_height = height; - if (host_depth_matches_server(host_screen)) { + if (host_depth_matches_server(scrpriv)) { EPHYR_DBG("Host matches server"); - return host_screen->ximg->data; + return scrpriv->ximg->data; } else { - EPHYR_DBG("server bpp %i", host_screen->server_depth >> 3); - host_screen->fb_data = - malloc(width * buffer_height * (host_screen->server_depth >> 3)); - return host_screen->fb_data; + EPHYR_DBG("server bpp %i", scrpriv->server_depth >> 3); + scrpriv->fb_data = + malloc(width * buffer_height * (scrpriv->server_depth >> 3)); + return scrpriv->fb_data; } } -static void hostx_paint_debug_rect(struct EphyrHostScreen *host_screen, +static void hostx_paint_debug_rect(KdScreenInfo *screen, int x, int y, int width, int height); void -hostx_paint_rect(EphyrScreenInfo screen, +hostx_paint_rect(KdScreenInfo *screen, int sx, int sy, int dx, int dy, int width, int height) { - struct EphyrHostScreen *host_screen = host_screen_from_screen_info(screen); + EphyrScrPriv *scrpriv = screen->driver; - EPHYR_DBG("painting in screen %d\n", host_screen->mynum); + EPHYR_DBG("painting in screen %d\n", scrpriv->mynum); /* * Copy the image data updated by the shadow layer @@ -748,7 +743,7 @@ hostx_paint_rect(EphyrScreenInfo screen, */ if (HostXWantDamageDebug) { - hostx_paint_debug_rect(host_screen, dx, dy, width, height); + hostx_paint_debug_rect(screen, dx, dy, width, height); } /* @@ -763,23 +758,23 @@ hostx_paint_rect(EphyrScreenInfo screen, * ... and it will be slower than the matching depth case. */ - if (!host_depth_matches_server(host_screen)) { - int x, y, idx, bytes_per_pixel = (host_screen->server_depth >> 3); + if (!host_depth_matches_server(scrpriv)) { + int x, y, idx, bytes_per_pixel = (scrpriv->server_depth >> 3); unsigned char r, g, b; unsigned long host_pixel; - EPHYR_DBG("Unmatched host depth host_screen=%p\n", host_screen); + EPHYR_DBG("Unmatched host depth scrpriv=%p\n", scrpriv); for (y = sy; y < sy + height; y++) for (x = sx; x < sx + width; x++) { idx = - (host_screen->win_width * y * bytes_per_pixel) + + (scrpriv->win_width * y * bytes_per_pixel) + (x * bytes_per_pixel); - switch (host_screen->server_depth) { + switch (scrpriv->server_depth) { case 16: { unsigned short pixel = - *(unsigned short *) (host_screen->fb_data + idx); + *(unsigned short *) (scrpriv->fb_data + idx); r = ((pixel & 0xf800) >> 8); g = ((pixel & 0x07e0) >> 3); @@ -787,14 +782,15 @@ hostx_paint_rect(EphyrScreenInfo screen, host_pixel = (r << 16) | (g << 8) | (b); - XPutPixel(host_screen->ximg, x, y, host_pixel); + xcb_image_put_pixel(scrpriv->ximg, x, y, host_pixel); break; } case 8: { unsigned char pixel = - *(unsigned char *) (host_screen->fb_data + idx); - XPutPixel(host_screen->ximg, x, y, HostX.cmap[pixel]); + *(unsigned char *) (scrpriv->fb_data + idx); + xcb_image_put_pixel(scrpriv->ximg, x, y, + HostX.cmap[pixel]); break; } default: @@ -804,23 +800,28 @@ hostx_paint_rect(EphyrScreenInfo screen, } if (HostX.have_shm) { - XShmPutImage(HostX.dpy, host_screen->win, - HostX.gc, host_screen->ximg, - sx, sy, dx, dy, width, height, False); + xcb_image_shm_put(HostX.conn, scrpriv->win, + HostX.gc, scrpriv->ximg, + scrpriv->shminfo, + sx, sy, dx, dy, width, height, FALSE); } else { - XPutImage(HostX.dpy, host_screen->win, HostX.gc, host_screen->ximg, - sx, sy, dx, dy, width, height); + xcb_image_put(HostX.conn, scrpriv->win, HostX.gc, scrpriv->ximg, + dx, dy, 0); } - XSync(HostX.dpy, False); + xcb_aux_sync(HostX.conn); } static void -hostx_paint_debug_rect(struct EphyrHostScreen *host_screen, +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; @@ -830,8 +831,10 @@ hostx_paint_debug_rect(struct EphyrHostScreen *host_screen, /* fprintf(stderr, "Xephyr updating: %i+%i %ix%i\n", x, y, width, height); */ - XFillRectangle(HostX.dpy, host_screen->win, HostX.gc, x, y, width, height); - XSync(HostX.dpy, False); + 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); @@ -840,304 +843,112 @@ hostx_paint_debug_rect(struct EphyrHostScreen *host_screen, void hostx_load_keymap(void) { - XID *keymap; - int host_width, min_keycode, max_keycode, width; - int i, j; + int min_keycode, max_keycode; - XDisplayKeycodes(HostX.dpy, &min_keycode, &max_keycode); + 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); - keymap = XGetKeyboardMapping(HostX.dpy, - min_keycode, - max_keycode - min_keycode + 1, &host_width); - - /* Try and copy the hosts keymap into our keymap to avoid loads - * of messing around. - * - * kdrive cannot can have more than 4 keysyms per keycode - * so we only copy at most the first 4 ( xorg has 6 per keycode, XVNC 2 ) - */ - width = (host_width > 4) ? 4 : host_width; - - ephyrKeySyms.map = (CARD32 *) calloc(sizeof(CARD32), - (max_keycode - min_keycode + 1) * - width); - if (!ephyrKeySyms.map) - goto out; - - for (i = 0; i < (max_keycode - min_keycode + 1); i++) - for (j = 0; j < width; j++) - ephyrKeySyms.map[(i * width) + j] = - (CARD32) keymap[(i * host_width) + j]; - - EPHYR_DBG("keymap width, host:%d kdrive:%d", host_width, width); - ephyrKeySyms.minKeyCode = min_keycode; ephyrKeySyms.maxKeyCode = max_keycode; - ephyrKeySyms.mapWidth = width; - - out: - XFree(keymap); } -static struct EphyrHostScreen * -host_screen_from_window(Window w) +xcb_connection_t * +hostx_get_xcbconn(void) { - int index = 0; - struct EphyrHostScreen *result = NULL; - - for (index = 0; index < HostX.n_screens; index++) { - if (HostX.screens[index].win == w - || HostX.screens[index].peer_win == w - || HostX.screens[index].win_pre_existing == w) { - result = &HostX.screens[index]; - goto out; - } - } - - out: - return result; + return HostX.conn; } int -hostx_get_event(EphyrHostXEvent * ev) -{ - XEvent xev; - static int grabbed_screen = -1; - - if (XPending(HostX.dpy)) { - XNextEvent(HostX.dpy, &xev); - - switch (xev.type) { - case Expose: - /* Not so great event compression, but works ok */ - while (XCheckTypedWindowEvent(HostX.dpy, xev.xexpose.window, - Expose, &xev)); - { - struct EphyrHostScreen *host_screen = - host_screen_from_window(xev.xexpose.window); - if (host_screen) { - hostx_paint_rect(host_screen->info, 0, 0, 0, 0, - host_screen->win_width, - host_screen->win_height); - } - else { - EPHYR_LOG_ERROR("failed to get host screen\n"); - ev->type = EPHYR_EV_EXPOSE; - ev->data.expose.window = xev.xexpose.window; - return 1; - } - } - return 0; - - case MotionNotify: - { - struct EphyrHostScreen *host_screen = - host_screen_from_window(xev.xmotion.window); - - ev->type = EPHYR_EV_MOUSE_MOTION; - ev->data.mouse_motion.x = xev.xmotion.x; - ev->data.mouse_motion.y = xev.xmotion.y; - ev->data.mouse_motion.window = xev.xmotion.window; - ev->data.mouse_motion.screen = - (host_screen ? host_screen->mynum : -1); - } - return 1; - - case ButtonPress: - ev->type = EPHYR_EV_MOUSE_PRESS; - ev->key_state = xev.xkey.state; - /* - * This is a bit hacky. will break for button 5 ( defined as 0x10 ) - * Check KD_BUTTON defines in kdrive.h - */ - ev->data.mouse_down.button_num = 1 << (xev.xbutton.button - 1); - return 1; - - case ButtonRelease: - ev->type = EPHYR_EV_MOUSE_RELEASE; - ev->key_state = xev.xkey.state; - ev->data.mouse_up.button_num = 1 << (xev.xbutton.button - 1); - return 1; - - case KeyPress: - { - ev->type = EPHYR_EV_KEY_PRESS; - ev->key_state = xev.xkey.state; - ev->data.key_down.scancode = xev.xkey.keycode; - return 1; - } - case KeyRelease: - - if ((XKeycodeToKeysym(HostX.dpy, xev.xkey.keycode, 0) == XK_Shift_L - || XKeycodeToKeysym(HostX.dpy, xev.xkey.keycode, - 0) == XK_Shift_R) - && (xev.xkey.state & ControlMask)) { - struct EphyrHostScreen *host_screen = - host_screen_from_window(xev.xexpose.window); - - if (grabbed_screen != -1) { - XUngrabKeyboard(HostX.dpy, CurrentTime); - XUngrabPointer(HostX.dpy, CurrentTime); - grabbed_screen = -1; - hostx_set_win_title(host_screen->info, - "(ctrl+shift grabs mouse and keyboard)"); - } - else { - /* Attempt grab */ - if (XGrabKeyboard(HostX.dpy, host_screen->win, True, - GrabModeAsync, - GrabModeAsync, CurrentTime) == 0) { - if (XGrabPointer(HostX.dpy, host_screen->win, True, - NoEventMask, - GrabModeAsync, - GrabModeAsync, - host_screen->win, None, - CurrentTime) == 0) { - grabbed_screen = host_screen->mynum; - hostx_set_win_title - (host_screen->info, - "(ctrl+shift releases mouse and keyboard)"); - } - else /* Failed pointer grabm ungrab keyboard */ - XUngrabKeyboard(HostX.dpy, CurrentTime); - } - } - } - - /* 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 togeather. - */ - ev->type = EPHYR_EV_KEY_RELEASE; - ev->key_state = xev.xkey.state; - ev->data.key_up.scancode = xev.xkey.keycode; - return 1; - - case ConfigureNotify: - { - struct EphyrHostScreen *host_screen; - - /* event compression as for Expose events, cause - * we don't want to resize the framebuffer for - * every single change */ - while (XCheckTypedWindowEvent(HostX.dpy, xev.xconfigure.window, - ConfigureNotify, &xev)); - host_screen = host_screen_from_window(xev.xconfigure.window); - - if (!host_screen || - (host_screen->win_pre_existing == None && !EphyrWantResize)) { - return 0; - } - - ev->type = EPHYR_EV_CONFIGURE; - ev->data.configure.width = xev.xconfigure.width; - ev->data.configure.height = xev.xconfigure.height; - ev->data.configure.window = xev.xconfigure.window; - ev->data.configure.screen = host_screen->mynum; - - return 1; - } - default: - break; - - } - } - return 0; -} - -void * -hostx_get_display(void) +hostx_get_screen(void) { - return HostX.dpy; + return HostX.screen; } 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; } - return HostX.screens[a_screen_number].win; + scrpriv = HostX.screens[a_screen_number]->driver; + return scrpriv->win; } int hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attrs) { - XWindowAttributes attrs; - - memset(&attrs, 0, sizeof(attrs)); - - if (!XGetWindowAttributes(hostx_get_display(), a_window, &attrs)) { - return FALSE; - } - a_attrs->x = attrs.x; - a_attrs->y = attrs.y; - a_attrs->width = attrs.width; - a_attrs->height = attrs.height; - if (attrs.visual) - a_attrs->visualid = attrs.visual->visualid; + 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_extension_info(const char *a_ext_name, - int *a_major_opcode, - int *a_first_event, int *a_first_error) -{ - if (!a_ext_name || !a_major_opcode || !a_first_event || !a_first_error) - return 0; - if (!XQueryExtension(HostX.dpy, - a_ext_name, - a_major_opcode, a_first_event, a_first_error)) { - return 0; - } - return 1; -} - -int hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries) { - Display *dpy = hostx_get_display(); - Bool is_ok = False; - XVisualInfo templ, *visuals = NULL; + Bool is_ok = FALSE; EphyrHostVisualInfo *host_visuals = NULL; - int nb_items = 0, i = 0; + 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 && dpy, False); + EPHYR_RETURN_VAL_IF_FAIL(a_visuals && a_num_entries, FALSE); EPHYR_LOG("enter\n"); - memset(&templ, 0, sizeof(templ)); - visuals = XGetVisualInfo(dpy, VisualNoMask, &templ, &nb_items); - if (!visuals) { - EPHYR_LOG_ERROR("host does not advertise any visual\n"); - goto out; + + 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 = + realloc(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); - host_visuals = calloc(nb_items, sizeof(EphyrHostVisualInfo)); - for (i = 0; i < nb_items; i++) { - host_visuals[i].visualid = visuals[i].visualid; - host_visuals[i].screen = visuals[i].screen; - host_visuals[i].depth = visuals[i].depth; - host_visuals[i].class = visuals[i].class; - host_visuals[i].red_mask = visuals[i].red_mask; - host_visuals[i].green_mask = visuals[i].green_mask; - host_visuals[i].blue_mask = visuals[i].blue_mask; - host_visuals[i].colormap_size = visuals[i].colormap_size; - host_visuals[i].bits_per_rgb = visuals[i].bits_per_rgb; - } *a_visuals = host_visuals; *a_num_entries = nb_items; host_visuals = NULL; is_ok = TRUE; - out: - if (visuals) { - XFree(visuals); - visuals = NULL; - } +out: free(host_visuals); host_visuals = NULL; EPHYR_LOG("leave\n"); @@ -1151,54 +962,58 @@ hostx_create_window(int a_screen_number, int a_visual_id, int *a_host_peer /*out parameter */ ) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - XVisualInfo *visual_info = NULL, visual_info_templ; - int visual_mask = VisualIDMask; - Window win = None; - int nb_visuals = 0, winmask = 0; - XSetWindowAttributes attrs; + 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(dpy && a_geometry, FALSE); + EPHYR_RETURN_VAL_IF_FAIL(screen && a_geometry, FALSE); EPHYR_LOG("enter\n"); - /*get visual */ - memset(&visual_info, 0, sizeof(visual_info)); - visual_info_templ.visualid = a_visual_id; - visual_info = XGetVisualInfo(dpy, visual_mask, - &visual_info_templ, &nb_visuals); - if (!visual_info) { - EPHYR_LOG_ERROR("argh, could not find a remote visual with id:%d\n", - a_visual_id); + 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; } - memset(&attrs, 0, sizeof(attrs)); - attrs.colormap = XCreateColormap(dpy, - RootWindow(dpy, - visual_info->screen), - visual_info->visual, AllocNone); - attrs.event_mask = ButtonPressMask - | ButtonReleaseMask - | PointerMotionMask | KeyPressMask | KeyReleaseMask | ExposureMask; - winmask = CWColormap | CWEventMask; - - win = XCreateWindow(dpy, hostx_get_window(a_screen_number), - a_geometry->x, a_geometry->y, - a_geometry->width, a_geometry->height, 0, - visual_info->depth, CopyFromParent, - visual_info->visual, winmask, &attrs); - if (win == None) { - EPHYR_LOG_ERROR("failed to create peer window\n"); - goto out; - } - if (HostX.screens[a_screen_number].peer_win == None) { - HostX.screens[a_screen_number].peer_win = win; + 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"); } - XFlush(dpy); - XMapWindow(dpy, win); + xcb_flush(HostX.conn); + xcb_map_window(HostX.conn, win); *a_host_peer = win; is_ok = TRUE; out: @@ -1209,26 +1024,31 @@ hostx_create_window(int a_screen_number, int hostx_destroy_window(int a_win) { - Display *dpy = hostx_get_display(); - - EPHYR_RETURN_VAL_IF_FAIL(dpy, FALSE); - XDestroyWindow(dpy, a_win); - XFlush(dpy); + xcb_destroy_window(HostX.conn, a_win); + xcb_flush(HostX.conn); return TRUE; } int hostx_set_window_geometry(int a_win, EphyrBox * a_geo) { - Display *dpy = hostx_get_display(); + 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(dpy && a_geo, FALSE); + 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); - XMoveWindow(dpy, a_win, a_geo->x, a_geo->y); - XResizeWindow(dpy, a_win, 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; } @@ -1238,15 +1058,16 @@ hostx_set_window_bounding_rectangles(int a_window, EphyrRect * a_rects, int a_num_rects) { Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); int i = 0; - XRectangle *rects = NULL; + xcb_rectangle_t *rects = NULL; - EPHYR_RETURN_VAL_IF_FAIL(dpy && a_rects, FALSE); + EPHYR_RETURN_VAL_IF_FAIL(a_rects, FALSE); EPHYR_LOG("enter. num rects:%d\n", a_num_rects); - rects = calloc(a_num_rects, sizeof(XRectangle)); + 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; @@ -1255,62 +1076,23 @@ hostx_set_window_bounding_rectangles(int a_window, 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); } - /*this aways returns 1 */ - XShapeCombineRectangles(dpy, a_window, ShapeBounding, 0, 0, - rects, a_num_rects, ShapeSet, YXBanded); - is_ok = TRUE; - - free(rects); - rects = NULL; - EPHYR_LOG("leave\n"); - return is_ok; -} - -int -hostx_set_window_clipping_rectangles(int a_window, - EphyrRect * a_rects, int a_num_rects) -{ - Bool is_ok = FALSE; - Display *dpy = hostx_get_display(); - int i = 0; - XRectangle *rects = NULL; - - EPHYR_RETURN_VAL_IF_FAIL(dpy && a_rects, FALSE); - - EPHYR_LOG("enter. num rects:%d\n", a_num_rects); - - rects = calloc(a_num_rects, sizeof(XRectangle)); - 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("clipped to rect[x:%d,y:%d,w:%d,h:%d]\n", - rects[i].x, rects[i].y, rects[i].width, rects[i].height); - } - /*this aways returns 1 */ - XShapeCombineRectangles(dpy, a_window, ShapeClip, 0, 0, - rects, a_num_rects, ShapeSet, YXBanded); + 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; } -int -hostx_has_xshape(void) -{ - int event_base = 0, error_base = 0; - Display *dpy = hostx_get_display(); - - if (!XShapeQueryExtension(dpy, &event_base, &error_base)) { - return FALSE; - } - return TRUE; -} - #ifdef XF86DRI typedef struct { int is_valid; @@ -1327,7 +1109,6 @@ hostx_allocate_resource_id_peer(int a_local_resource_id, { int i = 0; ResourcePair *peer = NULL; - Display *dpy = hostx_get_display(); /* * first make sure a resource peer @@ -1352,7 +1133,7 @@ hostx_allocate_resource_id_peer(int a_local_resource_id, } } if (peer) { - peer->remote_id = XAllocID(dpy); + peer->remote_id = xcb_generate_id(HostX.conn); peer->local_id = a_local_resource_id; peer->is_valid = TRUE; } @@ -1384,31 +1165,4 @@ hostx_get_resource_id_peer(int a_local_resource_id, int *a_remote_resource_id) return FALSE; } -int -hostx_has_dri(void) -{ - int event_base = 0, error_base = 0; - Display *dpy = hostx_get_display(); - - if (!dpy) - return FALSE; - - if (!XF86DRIQueryExtension(dpy, &event_base, &error_base)) { - return FALSE; - } - return TRUE; -} - -int -hostx_has_glx(void) -{ - Display *dpy = hostx_get_display(); - int event_base = 0, error_base = 0; - - if (!glXQueryExtension(dpy, &event_base, &error_base)) { - return FALSE; - } - return TRUE; -} - #endif /* XF86DRI */ diff --git a/xorg-server/hw/kdrive/ephyr/hostx.h b/xorg-server/hw/kdrive/ephyr/hostx.h index f47297c5d..e83323a0c 100644 --- a/xorg-server/hw/kdrive/ephyr/hostx.h +++ b/xorg-server/hw/kdrive/ephyr/hostx.h @@ -28,6 +28,8 @@ #include <X11/X.h> #include <X11/Xmd.h> +#include <xcb/xcb.h> +#include "ephyr.h" #define EPHYR_WANT_DEBUG 0 @@ -39,69 +41,12 @@ #endif typedef struct EphyrHostXVars EphyrHostXVars; -typedef struct EphyrHostXEvent EphyrHostXEvent; -typedef void *EphyrScreenInfo; -typedef enum EphyrHostXEventType { - EPHYR_EV_MOUSE_MOTION, - EPHYR_EV_MOUSE_PRESS, - EPHYR_EV_MOUSE_RELEASE, - EPHYR_EV_KEY_PRESS, - EPHYR_EV_KEY_RELEASE, - EPHYR_EV_EXPOSE, - EPHYR_EV_CONFIGURE, -} EphyrHostXEventType; - -/* I can't believe it's not a KeySymsRec. */ + typedef struct { int minKeyCode; int maxKeyCode; - int mapWidth; - CARD32 *map; } EphyrKeySyms; -struct EphyrHostXEvent { - EphyrHostXEventType type; - - union { - struct mouse_motion { - int x; - int y; - int screen; - int window; - } mouse_motion; - - struct mouse_down { - int button_num; - } mouse_down; - - struct mouse_up { - int button_num; - } mouse_up; - - struct key_up { - int scancode; - } key_up; - - struct key_down { - int scancode; - } key_down; - - struct expose { - int window; - } expose; - - struct configure { - int width; - int height; - int screen; - int window; - } configure; - - } data; - - int key_state; -}; - typedef struct { VisualID visualid; int screen; @@ -129,13 +74,13 @@ typedef struct { } EphyrRect; int - hostx_want_screen_size(EphyrScreenInfo screen, int *width, int *height); +hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height); int hostx_want_host_cursor(void); void - hostx_use_host_cursor(void); + hostx_use_sw_cursor(void); void hostx_use_fullscreen(void); @@ -144,7 +89,7 @@ int hostx_want_fullscreen(void); int - hostx_want_preexisting_window(EphyrScreenInfo screen); +hostx_want_preexisting_window(KdScreenInfo *screen); void hostx_use_preexisting_window(unsigned long win_id); @@ -162,52 +107,50 @@ int hostx_init(void); void - hostx_add_screen(EphyrScreenInfo screen, unsigned long win_id, int screen_num); +hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num); void hostx_set_display_name(char *name); void - hostx_set_screen_number(EphyrScreenInfo screen, int number); +hostx_set_screen_number(KdScreenInfo *screen, int number); void - hostx_set_win_title(EphyrScreenInfo screen, const char *extra_text); +hostx_set_win_title(KdScreenInfo *screen, const char *extra_text); int hostx_get_depth(void); int - hostx_get_server_depth(EphyrScreenInfo screen); - -void - hostx_set_server_depth(EphyrScreenInfo screen, int depth); +hostx_get_server_depth(KdScreenInfo *screen); int - hostx_get_bpp(void *info); +hostx_get_bpp(KdScreenInfo *screen); void - hostx_get_visual_masks(void *info, CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk); +hostx_get_visual_masks(KdScreenInfo *screen, + CARD32 *rmsk, CARD32 *gmsk, CARD32 *bmsk); void hostx_set_cmap_entry(unsigned char idx, unsigned char r, unsigned char g, unsigned char b); -void *hostx_screen_init(EphyrScreenInfo screen, +void *hostx_screen_init(KdScreenInfo *screen, int width, int height, int buffer_height, int *bytes_per_line, int *bits_per_pixel); void - -hostx_paint_rect(EphyrScreenInfo screen, +hostx_paint_rect(KdScreenInfo *screen, int sx, int sy, int dx, int dy, int width, int height); void hostx_load_keymap(void); -int - hostx_get_event(EphyrHostXEvent * ev); +xcb_connection_t * +hostx_get_xcbconn(void); -void *hostx_get_display(void); +int +hostx_get_screen(void); int hostx_get_window(int a_screen_number); @@ -216,11 +159,6 @@ int hostx_get_window_attributes(int a_window, EphyrHostWindowAttributes * a_attr); int - -hostx_get_extension_info(const char *a_ext_name, - int *a_major_opcode, - int *a_first_even, int *a_first_error); -int hostx_get_visuals_info(EphyrHostVisualInfo ** a_visuals, int *a_num_entries); int hostx_create_window(int a_screen_number, @@ -234,9 +172,7 @@ 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_set_window_clipping_rectangles(int a_window, - EphyrRect * a_rects, int a_num_rects); -int hostx_has_xshape(void); +int host_has_extension(xcb_extension_t *extension); #ifdef XF86DRI int hostx_lookup_peer_window(void *a_local_window, diff --git a/xorg-server/hw/kdrive/ephyr/xf86dri.h b/xorg-server/hw/kdrive/ephyr/xf86dri.h deleted file mode 100644 index 88d3f3bf1..000000000 --- a/xorg-server/hw/kdrive/ephyr/xf86dri.h +++ /dev/null @@ -1,124 +0,0 @@ -/* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.8 2002/10/30 12:51:25 alanh Exp $ */ -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -Copyright 2000 VA Linux Systems, 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, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/** - * \file xf86dri.h - * Protocol numbers and function prototypes for DRI X protocol. - * - * \author Kevin E. Martin <martin@valinux.com> - * \author Jens Owen <jens@tungstengraphics.com> - * \author Rickard E. (Rik) Faith <faith@valinux.com> - */ - -#ifndef _XF86DRI_H_ -#define _XF86DRI_H_ - -#include <X11/Xfuncproto.h> -#include <xf86drm.h> - -#define X_XF86DRIQueryVersion 0 -#define X_XF86DRIQueryDirectRenderingCapable 1 -#define X_XF86DRIOpenConnection 2 -#define X_XF86DRICloseConnection 3 -#define X_XF86DRIGetClientDriverName 4 -#define X_XF86DRICreateContext 5 -#define X_XF86DRIDestroyContext 6 -#define X_XF86DRICreateDrawable 7 -#define X_XF86DRIDestroyDrawable 8 -#define X_XF86DRIGetDrawableInfo 9 -#define X_XF86DRIGetDeviceInfo 10 -#define X_XF86DRIAuthConnection 11 -#define X_XF86DRIOpenFullScreen 12 /* Deprecated */ -#define X_XF86DRICloseFullScreen 13 /* Deprecated */ - -#define XF86DRINumberEvents 0 - -#define XF86DRIClientNotLocal 0 -#define XF86DRIOperationNotSupported 1 -#define XF86DRINumberErrors (XF86DRIOperationNotSupported + 1) - -#ifndef _XF86DRI_SERVER_ - -_XFUNCPROTOBEGIN - -Bool XF86DRIQueryExtension(Display * dpy, int *event_base, int *error_base); - -Bool XF86DRIQueryVersion(Display * dpy, int *majorVersion, int *minorVersion, - int *patchVersion); - -Bool XF86DRIQueryDirectRenderingCapable(Display * dpy, int screen, - Bool *isCapable); - -Bool XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA, - char **busIDString); - -Bool XF86DRIAuthConnection(Display * dpy, int screen, drm_magic_t magic); - -Bool XF86DRICloseConnection(Display * dpy, int screen); - -Bool XF86DRIGetClientDriverName(Display * dpy, int screen, - int *ddxDriverMajorVersion, - int *ddxDriverMinorVersion, - int *ddxDriverPatchVersion, - char **clientDriverName); - -Bool XF86DRICreateContext(Display * dpy, int screen, Visual * visual, - XID *ptr_to_returned_context_id, - drm_context_t * hHWContext); - -Bool XF86DRICreateContextWithConfig(Display * dpy, int screen, int configID, - XID *ptr_to_returned_context_id, - drm_context_t * hHWContext); - -extern GLboolean XF86DRIDestroyContext(Display * dpy, int screen, - XID context_id); - -extern GLboolean XF86DRICreateDrawable(Display * dpy, int screen, - XID drawable, - drm_drawable_t * hHWDrawable); - -extern GLboolean XF86DRIDestroyDrawable(Display * dpy, int screen, - XID drawable); - -Bool XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable, - unsigned int *index, unsigned int *stamp, - int *X, int *Y, int *W, int *H, - int *numClipRects, drm_clip_rect_t ** pClipRects, - int *backX, int *backY, - int *numBackClipRects, - drm_clip_rect_t ** pBackClipRects); - -Bool XF86DRIGetDeviceInfo(Display * dpy, int screen, - drm_handle_t * hFrameBuffer, int *fbOrigin, - int *fbSize, int *fbStride, int *devPrivateSize, - void **pDevPrivate); - -_XFUNCPROTOEND -#endif /* _XF86DRI_SERVER_ */ -#endif /* _XF86DRI_H_ */ |