2006-11-26 11:13:41 -07:00
|
|
|
/**************************************************************************
|
|
|
|
|
|
|
|
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:
|
|
|
|
* Jens Owen <jens@tungstengraphics.com>
|
|
|
|
* Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include <xorg-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "xf86.h"
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2006-12-16 13:09:36 -07:00
|
|
|
#include <sys/ioctl.h>
|
2007-11-24 10:55:21 -07:00
|
|
|
#include <errno.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
2006-12-16 13:09:36 -07:00
|
|
|
#include "xf86drm.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "misc.h"
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "extnsionst.h"
|
|
|
|
#include "colormapst.h"
|
|
|
|
#include "cursorstr.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "servermd.h"
|
|
|
|
#define _XF86DRI_SERVER_
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/dri/xf86driproto.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
#include "swaprep.h"
|
|
|
|
#include "xf86str.h"
|
|
|
|
#include "dri.h"
|
|
|
|
#include "sarea.h"
|
|
|
|
#include "dristruct.h"
|
|
|
|
#include "mi.h"
|
|
|
|
#include "mipointer.h"
|
2006-12-16 13:09:36 -07:00
|
|
|
#include "xf86_OSproc.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "inputstr.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "xf86VGAarbiter.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static int DRIEntPrivIndex = -1;
|
2010-12-05 08:36:02 -07:00
|
|
|
static DevPrivateKeyRec DRIScreenPrivKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define DRIScreenPrivKey (&DRIScreenPrivKeyRec)
|
|
|
|
static DevPrivateKeyRec DRIWindowPrivKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define DRIWindowPrivKey (&DRIWindowPrivKeyRec)
|
2006-11-26 11:13:41 -07:00
|
|
|
static unsigned long DRIGeneration = 0;
|
|
|
|
static unsigned int DRIDrawableValidationStamp = 0;
|
|
|
|
|
|
|
|
static RESTYPE DRIDrawablePrivResType;
|
|
|
|
static RESTYPE DRIContextPrivResType;
|
2012-06-10 07:21:05 -06:00
|
|
|
static void DRIDestroyDummyContext(ScreenPtr pScreen, Bool hasCtxPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2006-12-16 13:09:36 -07:00
|
|
|
drmServerInfo DRIDRMServerInfo;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Wrapper just like xf86DrvMsg, but
|
|
|
|
without the verbosity level checking.
|
|
|
|
This will make it easy to turn off some
|
|
|
|
messages later, based on verbosity
|
|
|
|
level. */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Since we're already referencing things from the XFree86 common layer in
|
|
|
|
* this file, we'd might as well just call xf86VDrvMsgVerb, and have
|
|
|
|
* consistent message formatting. The verbosity of these messages can be
|
|
|
|
* easily changed here.
|
|
|
|
*/
|
|
|
|
#define DRI_MSG_VERBOSITY 1
|
|
|
|
static void
|
|
|
|
DRIDrvMsg(int scrnIndex, MessageType type, const char *format, ...)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
va_list ap;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
va_start(ap, format);
|
|
|
|
xf86VDrvMsgVerb(scrnIndex, type, DRI_MSG_VERBOSITY, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static void
|
|
|
|
DRIOpenDRMCleanup(DRIEntPrivPtr pDRIEntPriv)
|
|
|
|
{
|
|
|
|
if (pDRIEntPriv->pLSAREA != NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
drmUnmap(pDRIEntPriv->pLSAREA, pDRIEntPriv->sAreaSize);
|
|
|
|
pDRIEntPriv->pLSAREA = NULL;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
if (pDRIEntPriv->hLSAREA != 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
drmRmMap(pDRIEntPriv->drmFD, pDRIEntPriv->hLSAREA);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
if (pDRIEntPriv->drmFD >= 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
drmClose(pDRIEntPriv->drmFD);
|
|
|
|
pDRIEntPriv->drmFD = 0;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DRIMasterFD(ScrnInfoPtr pScrn)
|
|
|
|
{
|
|
|
|
return DRI_ENT_PRIV(pScrn)->drmFD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
DRIMasterSareaPointer(ScrnInfoPtr pScrn)
|
|
|
|
{
|
|
|
|
return DRI_ENT_PRIV(pScrn)->pLSAREA;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_handle_t
|
|
|
|
DRIMasterSareaHandle(ScrnInfoPtr pScrn)
|
|
|
|
{
|
|
|
|
return DRI_ENT_PRIV(pScrn)->hLSAREA;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIOpenDRMMaster(ScrnInfoPtr pScrn,
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned long sAreaSize,
|
|
|
|
const char *busID, const char *drmDriverName)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
drmSetVersion saveSv, sv;
|
|
|
|
Bool drmWasAvailable;
|
|
|
|
DRIEntPrivPtr pDRIEntPriv;
|
|
|
|
DRIEntPrivRec tmp;
|
|
|
|
drmVersionPtr drmlibv;
|
|
|
|
int drmlibmajor, drmlibminor;
|
|
|
|
const char *openBusID;
|
|
|
|
int count;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (DRIEntPrivIndex == -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIEntPrivIndex = xf86AllocateEntityPrivateIndex();
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
pDRIEntPriv = DRI_ENT_PRIV(pScrn);
|
|
|
|
|
|
|
|
if (pDRIEntPriv && pDRIEntPriv->drmFD != -1)
|
2012-06-10 07:21:05 -06:00
|
|
|
return TRUE;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
drmWasAvailable = drmAvailable();
|
|
|
|
|
|
|
|
memset(&tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
/* Check the DRM lib version.
|
|
|
|
* drmGetLibVersion was not supported in version 1.0, so check for
|
|
|
|
* symbol first to avoid possible crash or hang.
|
|
|
|
*/
|
|
|
|
|
|
|
|
drmlibmajor = 1;
|
|
|
|
drmlibminor = 0;
|
|
|
|
if (xf86LoaderCheckSymbol("drmGetLibVersion")) {
|
2012-06-10 07:21:05 -06:00
|
|
|
drmlibv = drmGetLibVersion(-1);
|
|
|
|
if (drmlibv != NULL) {
|
|
|
|
drmlibmajor = drmlibv->version_major;
|
|
|
|
drmlibminor = drmlibv->version_minor;
|
|
|
|
drmFreeVersion(drmlibv);
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the libdrm can handle falling back to loading based on name
|
|
|
|
* if a busid string is passed.
|
|
|
|
*/
|
|
|
|
openBusID = (drmlibmajor == 1 && drmlibminor >= 2) ? busID : NULL;
|
|
|
|
|
|
|
|
tmp.drmFD = -1;
|
|
|
|
sv.drm_di_major = 1;
|
|
|
|
sv.drm_di_minor = 1;
|
|
|
|
sv.drm_dd_major = -1;
|
|
|
|
|
|
|
|
saveSv = sv;
|
|
|
|
count = 10;
|
|
|
|
while (count--) {
|
2012-06-10 07:21:05 -06:00
|
|
|
tmp.drmFD = drmOpen(drmDriverName, openBusID);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (tmp.drmFD < 0) {
|
|
|
|
DRIDrvMsg(-1, X_ERROR, "[drm] drmOpen failed.\n");
|
|
|
|
goto out_err;
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
err = drmSetInterfaceVersion(tmp.drmFD, &sv);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (err != -EPERM)
|
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
sv = saveSv;
|
|
|
|
drmClose(tmp.drmFD);
|
|
|
|
tmp.drmFD = -1;
|
|
|
|
usleep(100000);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tmp.drmFD <= 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(-1, X_ERROR, "[drm] DRM was busy with another master.\n");
|
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!drmWasAvailable) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(-1, X_INFO,
|
|
|
|
"[drm] loaded kernel module for \"%s\" driver.\n",
|
|
|
|
drmDriverName);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err != 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
sv.drm_di_major = 1;
|
|
|
|
sv.drm_di_minor = 0;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DRIDrvMsg(-1, X_INFO, "[drm] DRM interface version %d.%d\n",
|
2012-06-10 07:21:05 -06:00
|
|
|
sv.drm_di_major, sv.drm_di_minor);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
if (sv.drm_di_major == 1 && sv.drm_di_minor >= 1)
|
2012-06-10 07:21:05 -06:00
|
|
|
err = 0;
|
2007-11-24 10:55:21 -07:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
err = drmSetBusid(tmp.drmFD, busID);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
if (err) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(-1, X_ERROR, "[drm] Could not set DRM device bus ID.\n");
|
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a lock-containing sarea.
|
|
|
|
*/
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (drmAddMap(tmp.drmFD, 0, sAreaSize, DRM_SHM,
|
|
|
|
DRM_CONTAINS_LOCK, &tmp.hLSAREA) < 0) {
|
2007-11-24 10:55:21 -07:00
|
|
|
DRIDrvMsg(-1, X_INFO, "[drm] Could not create SAREA for DRM lock.\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
tmp.hLSAREA = 0;
|
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (drmMap(tmp.drmFD, tmp.hLSAREA, sAreaSize,
|
|
|
|
(drmAddressPtr) (&tmp.pLSAREA)) < 0) {
|
2007-11-24 10:55:21 -07:00
|
|
|
DRIDrvMsg(-1, X_INFO, "[drm] Mapping SAREA for DRM lock failed.\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
tmp.pLSAREA = NULL;
|
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(tmp.pLSAREA, 0, sAreaSize);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reserved contexts are handled by the first opened screen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp.resOwner = NULL;
|
|
|
|
|
|
|
|
if (!pDRIEntPriv)
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIEntPriv = xnfcalloc(sizeof(*pDRIEntPriv), 1);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
if (!pDRIEntPriv) {
|
|
|
|
DRIDrvMsg(-1, X_INFO, "[drm] Failed to allocate memory for "
|
2012-06-10 07:21:05 -06:00
|
|
|
"DRM device.\n");
|
|
|
|
goto out_err;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
*pDRIEntPriv = tmp;
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86GetEntityPrivate((pScrn)->entityList[0], DRIEntPrivIndex)->ptr =
|
|
|
|
pDRIEntPriv;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
DRIDrvMsg(-1, X_INFO, "[drm] DRM open master succeeded.\n");
|
|
|
|
return TRUE;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
out_err:
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
DRIOpenDRMCleanup(&tmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIClipNotifyAllDrawables(ScreenPtr pScreen);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
static void
|
|
|
|
dri_crtc_notify(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
DRIClipNotifyAllDrawables(pScreen);
|
|
|
|
xf86_unwrap_crtc_notify(pScreen, pDRIPriv->xf86_crtc_notify);
|
|
|
|
xf86_crtc_notify(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->xf86_crtc_notify =
|
|
|
|
xf86_wrap_crtc_notify(pScreen, dri_crtc_notify);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
Bool
|
|
|
|
DRIScreenInit(ScreenPtr pScreen, DRIInfoPtr pDRIInfo, int *pDRMFD)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv;
|
|
|
|
drm_context_t *reserved;
|
|
|
|
int reserved_count;
|
|
|
|
int i;
|
|
|
|
DRIEntPrivPtr pDRIEntPriv;
|
|
|
|
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
|
|
|
DRIContextFlags flags = 0;
|
|
|
|
DRIContextPrivPtr pDRIContextPriv;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* If the DRI extension is disabled, do not initialize the DRI */
|
|
|
|
if (noXFree86DRIExtension) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_WARNING,
|
|
|
|
"Direct rendering has been disabled.\n");
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!xf86VGAarbiterAllowDRI(pScreen)) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_WARNING,
|
|
|
|
"Direct rendering is not supported when VGA arb is necessary for the device\n");
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PANORAMIX
|
2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* If Xinerama is on, don't allow DRI to initialise. It won't be usable
|
|
|
|
* anyway.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!noPanoramiXExtension) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_WARNING,
|
|
|
|
"Direct rendering is not supported when Xinerama is enabled\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
#endif
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (!DRIOpenDRMMaster(pScrn, pDRIInfo->SAREASize,
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIInfo->busIdString, pDRIInfo->drmDriverName))
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
pDRIEntPriv = DRI_ENT_PRIV(pScrn);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
if (DRIGeneration != serverGeneration)
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIGeneration = serverGeneration;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
if (!dixRegisterPrivateKey(&DRIScreenPrivKeyRec, PRIVATE_SCREEN, 0))
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2010-12-05 08:36:02 -07:00
|
|
|
if (!dixRegisterPrivateKey(&DRIWindowPrivKeyRec, PRIVATE_WINDOW, 0))
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
pDRIPriv = (DRIScreenPrivPtr) calloc(1, sizeof(DRIScreenPrivRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!pDRIPriv) {
|
2012-06-10 07:21:05 -06:00
|
|
|
dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
|
2006-11-26 11:13:41 -07:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, pDRIPriv);
|
2007-11-24 10:55:21 -07:00
|
|
|
pDRIPriv->drmFD = pDRIEntPriv->drmFD;
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIPriv->directRenderingSupport = TRUE;
|
|
|
|
pDRIPriv->pDriverInfo = pDRIInfo;
|
|
|
|
pDRIPriv->nrWindows = 0;
|
2007-11-24 10:55:21 -07:00
|
|
|
pDRIPriv->nrWindowsVisible = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIPriv->fullscreen = NULL;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->createDummyCtx = pDRIInfo->createDummyCtx;
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIPriv->createDummyCtxPriv = pDRIInfo->createDummyCtxPriv;
|
|
|
|
|
|
|
|
pDRIPriv->grabbedDRILock = FALSE;
|
2007-11-24 10:55:21 -07:00
|
|
|
*pDRMFD = pDRIPriv->drmFD;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (pDRIEntPriv->sAreaGrabbed || pDRIInfo->allocSarea) {
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (drmAddMap(pDRIPriv->drmFD,
|
|
|
|
0,
|
|
|
|
pDRIPriv->pDriverInfo->SAREASize,
|
|
|
|
DRM_SHM, 0, &pDRIPriv->hSAREA) < 0) {
|
|
|
|
pDRIPriv->directRenderingSupport = FALSE;
|
|
|
|
dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
|
|
|
|
drmClose(pDRIPriv->drmFD);
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] drmAddMap failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[drm] added %d byte SAREA at %p\n",
|
|
|
|
pDRIPriv->pDriverInfo->SAREASize, pDRIPriv->hSAREA);
|
|
|
|
|
|
|
|
/* Backwards compat. */
|
|
|
|
if (drmMap(pDRIPriv->drmFD,
|
|
|
|
pDRIPriv->hSAREA,
|
|
|
|
pDRIPriv->pDriverInfo->SAREASize,
|
|
|
|
(drmAddressPtr) (&pDRIPriv->pSAREA)) < 0) {
|
|
|
|
pDRIPriv->directRenderingSupport = FALSE;
|
|
|
|
dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
|
|
|
|
drmClose(pDRIPriv->drmFD);
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] drmMap failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] mapped SAREA %p to %p\n",
|
|
|
|
pDRIPriv->hSAREA, pDRIPriv->pSAREA);
|
|
|
|
memset(pDRIPriv->pSAREA, 0, pDRIPriv->pDriverInfo->SAREASize);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] Using the DRM lock "
|
|
|
|
"SAREA also for drawables.\n");
|
|
|
|
pDRIPriv->hSAREA = pDRIEntPriv->hLSAREA;
|
|
|
|
pDRIPriv->pSAREA = (XF86DRISAREAPtr) pDRIEntPriv->pLSAREA;
|
|
|
|
pDRIEntPriv->sAreaGrabbed = TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
pDRIPriv->hLSAREA = pDRIEntPriv->hLSAREA;
|
|
|
|
pDRIPriv->pLSAREA = pDRIEntPriv->pLSAREA;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv->pDriverInfo->dontMapFrameBuffer) {
|
|
|
|
if (drmAddMap(pDRIPriv->drmFD,
|
|
|
|
(uintptr_t) pDRIPriv->pDriverInfo->
|
|
|
|
frameBufferPhysicalAddress,
|
|
|
|
pDRIPriv->pDriverInfo->frameBufferSize, DRM_FRAME_BUFFER,
|
|
|
|
0, &pDRIPriv->pDriverInfo->hFrameBuffer) < 0) {
|
|
|
|
pDRIPriv->directRenderingSupport = FALSE;
|
|
|
|
dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
|
|
|
|
drmUnmap(pDRIPriv->pSAREA, pDRIPriv->pDriverInfo->SAREASize);
|
|
|
|
drmClose(pDRIPriv->drmFD);
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] drmAddMap failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] framebuffer handle = %p\n",
|
|
|
|
pDRIPriv->pDriverInfo->hFrameBuffer);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[drm] framebuffer mapped by ddx driver\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (pDRIEntPriv->resOwner == NULL) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIEntPriv->resOwner = pScreen;
|
|
|
|
|
|
|
|
/* Add tags for reserved contexts */
|
|
|
|
if ((reserved = drmGetReservedContextList(pDRIPriv->drmFD,
|
|
|
|
&reserved_count))) {
|
|
|
|
int i;
|
|
|
|
void *tag;
|
|
|
|
|
|
|
|
for (i = 0; i < reserved_count; i++) {
|
|
|
|
tag = DRICreateContextPrivFromHandle(pScreen,
|
|
|
|
reserved[i],
|
|
|
|
DRI_CONTEXT_RESERVED);
|
|
|
|
drmAddContextTag(pDRIPriv->drmFD, reserved[i], tag);
|
|
|
|
}
|
|
|
|
drmFreeReservedContextList(reserved);
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[drm] added %d reserved context%s for kernel\n",
|
|
|
|
reserved_count, reserved_count > 1 ? "s" : "");
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* validate max drawable table entry set by driver */
|
|
|
|
if ((pDRIPriv->pDriverInfo->maxDrawableTableEntry <= 0) ||
|
|
|
|
(pDRIPriv->pDriverInfo->maxDrawableTableEntry > SAREA_MAX_DRAWABLES)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"Invalid max drawable table size set by driver: %d\n",
|
|
|
|
pDRIPriv->pDriverInfo->maxDrawableTableEntry);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize drawable tables (screen private and SAREA) */
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; i++) {
|
|
|
|
pDRIPriv->DRIDrawables[i] = NULL;
|
|
|
|
pDRIPriv->pSAREA->drawableTable[i].stamp = 0;
|
|
|
|
pDRIPriv->pSAREA->drawableTable[i].flags = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
pDRIPriv->pLockRefCount = &pDRIEntPriv->lockRefCount;
|
|
|
|
pDRIPriv->pLockingContext = &pDRIEntPriv->lockingContext;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (!pDRIEntPriv->keepFDOpen)
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIEntPriv->keepFDOpen = pDRIInfo->keepFDOpen;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
pDRIEntPriv->refCount++;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
/* Set up flags for DRICreateContextPriv */
|
2006-11-26 11:13:41 -07:00
|
|
|
switch (pDRIInfo->driverSwapMethod) {
|
2007-11-24 10:55:21 -07:00
|
|
|
case DRI_KERNEL_SWAP:
|
2012-06-10 07:21:05 -06:00
|
|
|
flags = DRI_CONTEXT_2DONLY;
|
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
case DRI_HIDE_X_CONTEXT:
|
2012-06-10 07:21:05 -06:00
|
|
|
flags = DRI_CONTEXT_PRESERVED;
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pDRIContextPriv = DRICreateContextPriv(pScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDRIPriv->myContext,
|
|
|
|
flags))) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR, "failed to create server context\n");
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
pDRIPriv->myContextPriv = pDRIContextPriv;
|
|
|
|
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
2012-06-10 07:21:05 -06:00
|
|
|
"X context handle = %p\n", pDRIPriv->myContext);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Now that we have created the X server's context, we can grab the
|
|
|
|
* hardware lock for the X server.
|
|
|
|
*/
|
|
|
|
DRILock(pScreen, 0);
|
|
|
|
pDRIPriv->grabbedDRILock = TRUE;
|
|
|
|
|
|
|
|
/* pointers so that we can prevent memory leaks later */
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->hiddenContextStore = NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIPriv->partial3DContextStore = NULL;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (pDRIInfo->driverSwapMethod) {
|
2006-11-26 11:13:41 -07:00
|
|
|
case DRI_HIDE_X_CONTEXT:
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Server will handle 3D swaps, and hide 2D swaps from kernel.
|
|
|
|
* Register server context as a preserved context.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* allocate memory for hidden context store */
|
|
|
|
pDRIPriv->hiddenContextStore
|
|
|
|
= (void *) calloc(1, pDRIInfo->contextSize);
|
|
|
|
if (!pDRIPriv->hiddenContextStore) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"failed to allocate hidden context\n");
|
|
|
|
DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate memory for partial 3D context store */
|
|
|
|
pDRIPriv->partial3DContextStore
|
|
|
|
= (void *) calloc(1, pDRIInfo->contextSize);
|
|
|
|
if (!pDRIPriv->partial3DContextStore) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[DRI] failed to allocate partial 3D context\n");
|
|
|
|
free(pDRIPriv->hiddenContextStore);
|
|
|
|
DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save initial context store */
|
|
|
|
if (pDRIInfo->SwapContext) {
|
|
|
|
(*pDRIInfo->SwapContext) (pScreen,
|
|
|
|
DRI_NO_SYNC,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->hiddenContextStore,
|
|
|
|
DRI_NO_CONTEXT, NULL);
|
|
|
|
}
|
|
|
|
/* fall through */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
case DRI_SERVER_SWAP:
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIFinishScreenInit(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* Wrap DRI support */
|
|
|
|
if (pDRIInfo->wrap.ValidateTree) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
|
|
|
|
pScreen->ValidateTree = pDRIInfo->wrap.ValidateTree;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.PostValidateTree) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
|
|
|
|
pScreen->PostValidateTree = pDRIInfo->wrap.PostValidateTree;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.WindowExposures) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
|
|
|
|
pScreen->WindowExposures = pDRIInfo->wrap.WindowExposures;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->DestroyWindow = pScreen->DestroyWindow;
|
|
|
|
pScreen->DestroyWindow = DRIDestroyWindow;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
pDRIPriv->xf86_crtc_notify = xf86_wrap_crtc_notify(pScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
dri_crtc_notify);
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
if (pDRIInfo->wrap.CopyWindow) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
|
|
|
|
pScreen->CopyWindow = pDRIInfo->wrap.CopyWindow;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.ClipNotify) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
|
|
|
|
pScreen->ClipNotify = pDRIInfo->wrap.ClipNotify;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.AdjustFrame) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
|
|
|
|
|
|
|
pDRIPriv->wrap.AdjustFrame = pScrn->AdjustFrame;
|
|
|
|
pScrn->AdjustFrame = pDRIInfo->wrap.AdjustFrame;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
pDRIPriv->wrapped = TRUE;
|
|
|
|
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[DRI] installation complete\n");
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRICloseScreen(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIInfoPtr pDRIInfo;
|
|
|
|
drm_context_t *reserved;
|
|
|
|
int reserved_count;
|
|
|
|
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
|
|
|
DRIEntPrivPtr pDRIEntPriv = DRI_ENT_PRIV(pScrn);
|
2007-11-24 10:55:21 -07:00
|
|
|
Bool closeMaster;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (pDRIPriv) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
pDRIInfo = pDRIPriv->pDriverInfo;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->wrapped) {
|
|
|
|
/* Unwrap DRI Functions */
|
|
|
|
if (pDRIInfo->wrap.ValidateTree) {
|
|
|
|
pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
|
|
|
|
pDRIPriv->wrap.ValidateTree = NULL;
|
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.PostValidateTree) {
|
|
|
|
pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
|
|
|
|
pDRIPriv->wrap.PostValidateTree = NULL;
|
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.WindowExposures) {
|
|
|
|
pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
|
|
|
|
pDRIPriv->wrap.WindowExposures = NULL;
|
|
|
|
}
|
|
|
|
if (pDRIPriv->DestroyWindow) {
|
|
|
|
pScreen->DestroyWindow = pDRIPriv->DestroyWindow;
|
|
|
|
pDRIPriv->DestroyWindow = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
xf86_unwrap_crtc_notify(pScreen, pDRIPriv->xf86_crtc_notify);
|
|
|
|
|
|
|
|
if (pDRIInfo->wrap.CopyWindow) {
|
|
|
|
pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow;
|
|
|
|
pDRIPriv->wrap.CopyWindow = NULL;
|
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.ClipNotify) {
|
|
|
|
pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify;
|
|
|
|
pDRIPriv->wrap.ClipNotify = NULL;
|
|
|
|
}
|
|
|
|
if (pDRIInfo->wrap.AdjustFrame) {
|
|
|
|
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
|
|
|
|
|
|
|
pScrn->AdjustFrame = pDRIPriv->wrap.AdjustFrame;
|
|
|
|
pDRIPriv->wrap.AdjustFrame = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pDRIPriv->wrapped = FALSE;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDRIPriv->dummyCtxPriv && pDRIPriv->createDummyCtx) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDestroyDummyContext(pScreen, pDRIPriv->createDummyCtxPriv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!DRIDestroyContextPriv(pDRIPriv->myContextPriv)) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"failed to destroy server context\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove tags for reserved contexts */
|
|
|
|
if (pDRIEntPriv->resOwner == pScreen) {
|
|
|
|
pDRIEntPriv->resOwner = NULL;
|
|
|
|
|
|
|
|
if ((reserved = drmGetReservedContextList(pDRIPriv->drmFD,
|
|
|
|
&reserved_count))) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < reserved_count; i++) {
|
|
|
|
DRIDestroyContextPriv(drmGetContextTag(pDRIPriv->drmFD,
|
|
|
|
reserved[i]));
|
|
|
|
}
|
|
|
|
drmFreeReservedContextList(reserved);
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[drm] removed %d reserved context%s for kernel\n",
|
|
|
|
reserved_count, reserved_count > 1 ? "s" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure signals get unblocked etc. */
|
|
|
|
drmUnlock(pDRIPriv->drmFD, pDRIPriv->myContext);
|
|
|
|
pDRIPriv->pLockRefCount = NULL;
|
|
|
|
closeMaster = (--pDRIEntPriv->refCount == 0) &&
|
|
|
|
!pDRIEntPriv->keepFDOpen;
|
|
|
|
if (closeMaster || pDRIPriv->hSAREA != pDRIEntPriv->hLSAREA) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[drm] unmapping %d bytes of SAREA %p at %p\n",
|
|
|
|
pDRIInfo->SAREASize, pDRIPriv->hSAREA, pDRIPriv->pSAREA);
|
|
|
|
if (drmUnmap(pDRIPriv->pSAREA, pDRIInfo->SAREASize)) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[drm] unable to unmap %d bytes"
|
|
|
|
" of SAREA %p at %p\n",
|
|
|
|
pDRIInfo->SAREASize,
|
|
|
|
pDRIPriv->hSAREA, pDRIPriv->pSAREA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pDRIEntPriv->sAreaGrabbed = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closeMaster || (pDRIEntPriv->drmFD != pDRIPriv->drmFD)) {
|
|
|
|
drmClose(pDRIPriv->drmFD);
|
|
|
|
if (pDRIEntPriv->drmFD == pDRIPriv->drmFD) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO, "[drm] Closed DRM master.\n");
|
|
|
|
pDRIEntPriv->drmFD = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pDRIPriv);
|
|
|
|
dixSetPrivate(&pScreen->devPrivates, DRIScreenPrivKey, NULL);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-16 13:09:36 -07:00
|
|
|
#define DRM_MSG_VERBOSITY 3
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static int
|
|
|
|
dri_drm_debug_print(const char *format, va_list ap)
|
2006-12-16 13:09:36 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
xf86VDrvMsgVerb(-1, X_NONE, DRM_MSG_VERBOSITY, format, ap);
|
|
|
|
return 0;
|
2006-12-16 13:09:36 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dri_drm_get_perms(gid_t * group, mode_t * mode)
|
2006-12-16 13:09:36 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
*group = xf86ConfigDRI.group;
|
|
|
|
*mode = xf86ConfigDRI.mode;
|
2006-12-16 13:09:36 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
drmServerInfo DRIDRMServerInfo = {
|
|
|
|
dri_drm_debug_print,
|
|
|
|
xf86LoadKernelModule,
|
|
|
|
dri_drm_get_perms,
|
2006-12-16 13:09:36 -07:00
|
|
|
};
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
Bool
|
|
|
|
DRIExtensionInit(void)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
if (DRIGeneration != serverGeneration) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
DRIDrawablePrivResType = CreateNewResourceType(DRIDrawablePrivDelete,
|
2012-06-10 07:21:05 -06:00
|
|
|
"DRIDrawable");
|
2010-07-27 13:02:24 -06:00
|
|
|
DRIContextPrivResType = CreateNewResourceType(DRIContextPrivDelete,
|
2012-06-10 07:21:05 -06:00
|
|
|
"DRIContext");
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (!DRIDrawablePrivResType || !DRIContextPrivResType)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
RegisterBlockAndWakeupHandlers(DRIBlockHandler, DRIWakeupHandler, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIReset(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This stub routine is called when the X Server recycles, resources
|
|
|
|
* allocated by DRIExtensionInit need to be managed here.
|
|
|
|
*
|
|
|
|
* Currently this routine is a stub because all the interesting resources
|
|
|
|
* are managed via the screen init process.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIQueryDirectRenderingCapable(ScreenPtr pScreen, Bool *isCapable)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
if (pDRIPriv)
|
2012-06-10 07:21:05 -06:00
|
|
|
*isCapable = pDRIPriv->directRenderingSupport;
|
2006-11-26 11:13:41 -07:00
|
|
|
else
|
2012-06-10 07:21:05 -06:00
|
|
|
*isCapable = FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIOpenConnection(ScreenPtr pScreen, drm_handle_t * hSAREA, char **busIdString)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
*hSAREA = pDRIPriv->hSAREA;
|
|
|
|
*busIdString = pDRIPriv->pDriverInfo->busIdString;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIAuthConnection(ScreenPtr pScreen, drm_magic_t magic)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (drmAuthMagic(pDRIPriv->drmFD, magic))
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRICloseConnection(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIGetClientDriverName(ScreenPtr pScreen,
|
|
|
|
int *ddxDriverMajorVersion,
|
|
|
|
int *ddxDriverMinorVersion,
|
2012-06-10 07:21:05 -06:00
|
|
|
int *ddxDriverPatchVersion, char **clientDriverName)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
*ddxDriverMajorVersion = pDRIPriv->pDriverInfo->ddxDriverMajorVersion;
|
|
|
|
*ddxDriverMinorVersion = pDRIPriv->pDriverInfo->ddxDriverMinorVersion;
|
|
|
|
*ddxDriverPatchVersion = pDRIPriv->pDriverInfo->ddxDriverPatchVersion;
|
2012-06-10 07:21:05 -06:00
|
|
|
*clientDriverName = pDRIPriv->pDriverInfo->clientDriverName;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DRICreateContextPriv and DRICreateContextPrivFromHandle are helper
|
|
|
|
functions that layer on drmCreateContext and drmAddContextTag.
|
|
|
|
|
|
|
|
DRICreateContextPriv always creates a kernel drm_context_t and then calls
|
|
|
|
DRICreateContextPrivFromHandle to create a DRIContextPriv structure for
|
2010-12-05 08:36:02 -07:00
|
|
|
DRI tracking. For the SIGIO handler, the drm_context_t is associated with
|
|
|
|
DRIContextPrivPtr. Any special flags are stored in the DRIContextPriv
|
2006-11-26 11:13:41 -07:00
|
|
|
area and are passed to the kernel (if necessary).
|
|
|
|
|
|
|
|
DRICreateContextPriv returns a pointer to newly allocated
|
|
|
|
DRIContextPriv, and returns the kernel drm_context_t in pHWContext. */
|
|
|
|
|
|
|
|
DRIContextPrivPtr
|
|
|
|
DRICreateContextPriv(ScreenPtr pScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
drm_context_t * pHWContext, DRIContextFlags flags)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (drmCreateContext(pDRIPriv->drmFD, pHWContext)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return DRICreateContextPrivFromHandle(pScreen, *pHWContext, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
DRIContextPrivPtr
|
|
|
|
DRICreateContextPrivFromHandle(ScreenPtr pScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
drm_context_t hHWContext, DRIContextFlags flags)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
DRIContextPrivPtr pDRIContextPriv;
|
2012-06-10 07:21:05 -06:00
|
|
|
int contextPrivSize;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
contextPrivSize = sizeof(DRIContextPrivRec) +
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->pDriverInfo->contextSize;
|
2010-12-05 08:36:02 -07:00
|
|
|
if (!(pDRIContextPriv = calloc(1, contextPrivSize))) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIContextPriv->pContextStore = (void *) (pDRIContextPriv + 1);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
drmAddContextTag(pDRIPriv->drmFD, hHWContext, pDRIContextPriv);
|
|
|
|
|
|
|
|
pDRIContextPriv->hwContext = hHWContext;
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIContextPriv->pScreen = pScreen;
|
|
|
|
pDRIContextPriv->flags = flags;
|
|
|
|
pDRIContextPriv->valid3D = FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (flags & DRI_CONTEXT_2DONLY) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (drmSetContextFlags(pDRIPriv->drmFD, hHWContext, DRM_CONTEXT_2DONLY)) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[drm] failed to set 2D context flag\n");
|
|
|
|
DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (flags & DRI_CONTEXT_PRESERVED) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (drmSetContextFlags(pDRIPriv->drmFD,
|
|
|
|
hHWContext, DRM_CONTEXT_PRESERVED)) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[drm] failed to set preserved flag\n");
|
|
|
|
DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return pDRIContextPriv;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIDestroyContextPriv(DRIContextPrivPtr pDRIContextPriv)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIContextPriv)
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
pDRIPriv = DRI_SCREEN_PRIV(pDRIContextPriv->pScreen);
|
|
|
|
|
|
|
|
if (!(pDRIContextPriv->flags & DRI_CONTEXT_RESERVED)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Don't delete reserved contexts from
|
|
|
|
kernel area -- the kernel manages its
|
|
|
|
reserved contexts itself. */
|
|
|
|
if (drmDestroyContext(pDRIPriv->drmFD, pDRIContextPriv->hwContext))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the tag last to prevent a race
|
|
|
|
condition where the context has pending
|
|
|
|
buffers. The context can't be re-used
|
|
|
|
while in this thread, but buffers can be
|
|
|
|
dispatched asynchronously. */
|
2006-11-26 11:13:41 -07:00
|
|
|
drmDelContextTag(pDRIPriv->drmFD, pDRIContextPriv->hwContext);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(pDRIContextPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
DRICreateDummyContext(ScreenPtr pScreen, Bool needCtxPriv)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIContextPrivPtr pDRIContextPriv;
|
|
|
|
void *contextStore;
|
|
|
|
|
|
|
|
if (!(pDRIContextPriv =
|
2012-06-10 07:21:05 -06:00
|
|
|
DRICreateContextPriv(pScreen, &pDRIPriv->pSAREA->dummy_context, 0))) {
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
contextStore = DRIGetContextStore(pDRIContextPriv);
|
|
|
|
if (pDRIPriv->pDriverInfo->CreateContext && needCtxPriv) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv->pDriverInfo->CreateContext(pScreen, NULL,
|
|
|
|
pDRIPriv->pSAREA->
|
|
|
|
dummy_context, NULL,
|
|
|
|
(DRIContextType) (long)
|
|
|
|
contextStore)) {
|
|
|
|
DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pDRIPriv->dummyCtxPriv = pDRIContextPriv;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRIDestroyDummyContext(ScreenPtr pScreen, Bool hasCtxPriv)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIContextPrivPtr pDRIContextPriv = pDRIPriv->dummyCtxPriv;
|
|
|
|
void *contextStore;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIContextPriv)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (pDRIPriv->pDriverInfo->DestroyContext && hasCtxPriv) {
|
2012-06-10 07:21:05 -06:00
|
|
|
contextStore = DRIGetContextStore(pDRIContextPriv);
|
|
|
|
pDRIPriv->pDriverInfo->DestroyContext(pDRIContextPriv->pScreen,
|
|
|
|
pDRIContextPriv->hwContext,
|
|
|
|
(DRIContextType) (long)
|
|
|
|
contextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DRIDestroyContextPriv(pDRIPriv->dummyCtxPriv);
|
|
|
|
pDRIPriv->dummyCtxPriv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRICreateContext(ScreenPtr pScreen, VisualPtr visual,
|
|
|
|
XID context, drm_context_t * pHWContext)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIContextPrivPtr pDRIContextPriv;
|
|
|
|
void *contextStore;
|
|
|
|
|
|
|
|
if (pDRIPriv->createDummyCtx && !pDRIPriv->dummyCtxPriv) {
|
|
|
|
if (!DRICreateDummyContext(pScreen, pDRIPriv->createDummyCtxPriv)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[drm] Could not create dummy context\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pDRIContextPriv = DRICreateContextPriv(pScreen, pHWContext, 0))) {
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
contextStore = DRIGetContextStore(pDRIContextPriv);
|
|
|
|
if (pDRIPriv->pDriverInfo->CreateContext) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!((*pDRIPriv->pDriverInfo->CreateContext) (pScreen, NULL,
|
|
|
|
*pHWContext, NULL,
|
|
|
|
(DRIContextType) (long)
|
|
|
|
contextStore))) {
|
|
|
|
DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* track this in case the client dies before cleanup */
|
2012-06-10 07:21:05 -06:00
|
|
|
AddResource(context, DRIContextPrivResType, (pointer) pDRIContextPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIDestroyContext(ScreenPtr pScreen, XID context)
|
|
|
|
{
|
|
|
|
FreeResourceByType(context, DRIContextPrivResType, FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DRIContextPrivDelete is called by the resource manager. */
|
|
|
|
Bool
|
|
|
|
DRIContextPrivDelete(pointer pResource, XID id)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIContextPrivPtr pDRIContextPriv = (DRIContextPrivPtr) pResource;
|
2006-11-26 11:13:41 -07:00
|
|
|
DRIScreenPrivPtr pDRIPriv;
|
|
|
|
void *contextStore;
|
|
|
|
|
|
|
|
pDRIPriv = DRI_SCREEN_PRIV(pDRIContextPriv->pScreen);
|
|
|
|
if (pDRIPriv->pDriverInfo->DestroyContext) {
|
2012-06-10 07:21:05 -06:00
|
|
|
contextStore = DRIGetContextStore(pDRIContextPriv);
|
|
|
|
pDRIPriv->pDriverInfo->DestroyContext(pDRIContextPriv->pScreen,
|
|
|
|
pDRIContextPriv->hwContext,
|
|
|
|
(DRIContextType) (long)
|
|
|
|
contextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return DRIDestroyContextPriv(pDRIContextPriv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This walks the drawable timestamp array and invalidates all of them
|
|
|
|
* in the case of transition from private to shared backbuffers. It's
|
|
|
|
* not necessary for correctness, because DRIClipNotify gets called in
|
|
|
|
* time to prevent any conflict, but the transition from
|
|
|
|
* shared->private is sometimes missed if we don't do this.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
DRIClipNotifyAllDrawables(ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < pDRIPriv->pDriverInfo->maxDrawableTableEntry; i++) {
|
|
|
|
pDRIPriv->pSAREA->drawableTable[i].stamp = DRIDrawableValidationStamp++;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRITransitionToSharedBuffers(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIClipNotifyAllDrawables(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDRIInfo->TransitionSingleToMulti3D)
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIInfo->TransitionSingleToMulti3D(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRITransitionToPrivateBuffers(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIClipNotifyAllDrawables(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDRIInfo->TransitionMultiToSingle3D)
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIInfo->TransitionMultiToSingle3D(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRITransitionTo3d(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIClipNotifyAllDrawables(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDRIInfo->TransitionTo3d)
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIInfo->TransitionTo3d(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRITransitionTo2d(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIClipNotifyAllDrawables(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDRIInfo->TransitionTo2d)
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIInfo->TransitionTo2d(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static int
|
|
|
|
DRIDCNTreeTraversal(WindowPtr pWin, pointer data)
|
|
|
|
{
|
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
|
|
|
|
|
|
|
|
if (pDRIDrawablePriv) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (RegionNumRects(&pWin->clipList) > 0) {
|
|
|
|
WindowPtr *pDRIWindows = (WindowPtr *) data;
|
|
|
|
int i = 0;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
while (pDRIWindows[i])
|
|
|
|
i++;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIWindows[i] = pWin;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->nrWalked++;
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->nrWindows == pDRIPriv->nrWalked)
|
|
|
|
return WT_STOPWALKING;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return WT_WALKCHILDREN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRIDriverClipNotify(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
if (pDRIPriv->pDriverInfo->ClipNotify) {
|
2012-06-10 07:21:05 -06:00
|
|
|
WindowPtr *pDRIWindows = calloc(sizeof(WindowPtr), pDRIPriv->nrWindows);
|
|
|
|
DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->nrWindows > 0) {
|
|
|
|
pDRIPriv->nrWalked = 0;
|
|
|
|
TraverseTree(pScreen->root, DRIDCNTreeTraversal,
|
|
|
|
(pointer) pDRIWindows);
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIInfo->ClipNotify(pScreen, pDRIWindows, pDRIPriv->nrWindows);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
free(pDRIWindows);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRIIncreaseNumberVisible(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
switch (++pDRIPriv->nrWindowsVisible) {
|
|
|
|
case 1:
|
2012-06-10 07:21:05 -06:00
|
|
|
DRITransitionTo3d(pScreen);
|
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
case 2:
|
2012-06-10 07:21:05 -06:00
|
|
|
DRITransitionToSharedBuffers(pScreen);
|
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DRIDriverClipNotify(pScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRIDecreaseNumberVisible(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
switch (--pDRIPriv->nrWindowsVisible) {
|
|
|
|
case 0:
|
2012-06-10 07:21:05 -06:00
|
|
|
DRITransitionTo2d(pScreen);
|
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
case 1:
|
2012-06-10 07:21:05 -06:00
|
|
|
DRITransitionToPrivateBuffers(pScreen);
|
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DRIDriverClipNotify(pScreen);
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
Bool
|
2007-11-24 10:55:21 -07:00
|
|
|
DRICreateDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
drm_drawable_t * hHWDrawable)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv;
|
|
|
|
WindowPtr pWin;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDrawable->type == DRAWABLE_WINDOW) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pWin = (WindowPtr) pDrawable;
|
|
|
|
if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
|
|
|
|
pDRIDrawablePriv->refCount++;
|
|
|
|
|
|
|
|
if (!pDRIDrawablePriv->hwDrawable) {
|
|
|
|
drmCreateDrawable(pDRIPriv->drmFD,
|
|
|
|
&pDRIDrawablePriv->hwDrawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* allocate a DRI Window Private record */
|
|
|
|
if (!(pDRIDrawablePriv = malloc(sizeof(DRIDrawablePrivRec)))) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only create a drm_drawable_t once */
|
|
|
|
if (drmCreateDrawable(pDRIPriv->drmFD,
|
|
|
|
&pDRIDrawablePriv->hwDrawable)) {
|
|
|
|
free(pDRIDrawablePriv);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add it to the list of DRI drawables for this screen */
|
|
|
|
pDRIDrawablePriv->pScreen = pScreen;
|
|
|
|
pDRIDrawablePriv->refCount = 1;
|
|
|
|
pDRIDrawablePriv->drawableIndex = -1;
|
|
|
|
pDRIDrawablePriv->nrects = RegionNumRects(&pWin->clipList);
|
|
|
|
|
|
|
|
/* save private off of preallocated index */
|
|
|
|
dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey,
|
|
|
|
pDRIDrawablePriv);
|
|
|
|
pDRIPriv->nrWindows++;
|
|
|
|
|
|
|
|
if (pDRIDrawablePriv->nrects)
|
|
|
|
DRIIncreaseNumberVisible(pScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* track this in case the client dies */
|
|
|
|
AddResource(FakeClientID(client->index), DRIDrawablePrivResType,
|
|
|
|
(pointer) (intptr_t) pDrawable->id);
|
|
|
|
|
|
|
|
if (pDRIDrawablePriv->hwDrawable) {
|
|
|
|
drmUpdateDrawableInfo(pDRIPriv->drmFD,
|
|
|
|
pDRIDrawablePriv->hwDrawable,
|
|
|
|
DRM_DRAWABLE_CLIPRECTS,
|
|
|
|
RegionNumRects(&pWin->clipList),
|
|
|
|
RegionRects(&pWin->clipList));
|
|
|
|
*hHWDrawable = pDRIDrawablePriv->hwDrawable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pDrawable->type != DRAWABLE_PIXMAP) { /* PBuffer */
|
|
|
|
/* NOT_DONE */
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
static void
|
|
|
|
DRIDrawablePrivDestroy(WindowPtr pWin)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
|
|
|
|
ScreenPtr pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv;
|
|
|
|
|
|
|
|
if (!pDRIDrawablePriv)
|
2012-06-10 07:21:05 -06:00
|
|
|
return;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
pScreen = pWin->drawable.pScreen;
|
|
|
|
pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
if (pDRIDrawablePriv->drawableIndex != -1) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* bump stamp to force outstanding 3D requests to resync */
|
|
|
|
pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp
|
|
|
|
= DRIDrawableValidationStamp++;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* release drawable table entry */
|
|
|
|
pDRIPriv->DRIDrawables[pDRIDrawablePriv->drawableIndex] = NULL;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pDRIPriv->nrWindows--;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
if (pDRIDrawablePriv->nrects)
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDecreaseNumberVisible(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
drmDestroyDrawable(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(pDRIDrawablePriv);
|
2008-11-02 08:26:08 -07:00
|
|
|
dixSetPrivate(&pWin->devPrivates, DRIWindowPrivKey, NULL);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
DRIDestroyDrawableCB(pointer value, XID id, pointer data)
|
|
|
|
{
|
|
|
|
if (value == data) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* This calls back DRIDrawablePrivDelete which frees private area */
|
|
|
|
FreeResourceByType(id, DRIDrawablePrivResType, FALSE);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return TRUE;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIDestroyDrawable(ScreenPtr pScreen, ClientPtr client, DrawablePtr pDrawable)
|
|
|
|
{
|
2006-11-26 11:13:41 -07:00
|
|
|
if (pDrawable->type == DRAWABLE_WINDOW) {
|
2012-06-10 07:21:05 -06:00
|
|
|
LookupClientResourceComplex(client, DRIDrawablePrivResType,
|
|
|
|
DRIDestroyDrawableCB,
|
|
|
|
(pointer) (intptr_t) pDrawable->id);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else { /* pixmap (or for GLX 1.3, a PBuffer) */
|
|
|
|
/* NOT_DONE */
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIDrawablePrivDelete(pointer pResource, XID id)
|
|
|
|
{
|
2007-11-24 10:55:21 -07:00
|
|
|
WindowPtr pWin;
|
2010-07-27 13:02:24 -06:00
|
|
|
int rc;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
/* For DRIDrawablePrivResType, the XID is the client's fake ID. The
|
|
|
|
* important XID is the value in pResource. */
|
2012-06-10 07:21:05 -06:00
|
|
|
id = (XID) (intptr_t) pResource;
|
2010-07-27 13:02:24 -06:00
|
|
|
rc = dixLookupWindow(&pWin, id, serverClient, DixGetAttrAccess);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (rc == Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrawablePrivPtr pDRIDrwPriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIDrwPriv)
|
|
|
|
return FALSE;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (--pDRIDrwPriv->refCount == 0)
|
|
|
|
DRIDrawablePrivDestroy(pWin);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else { /* pixmap (or for GLX 1.3, a PBuffer) */
|
|
|
|
/* NOT_DONE */
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIGetDrawableInfo(ScreenPtr pScreen,
|
|
|
|
DrawablePtr pDrawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned int *index,
|
|
|
|
unsigned int *stamp,
|
|
|
|
int *X,
|
|
|
|
int *Y,
|
|
|
|
int *W,
|
|
|
|
int *H,
|
|
|
|
int *numClipRects,
|
2006-11-26 11:13:41 -07:00
|
|
|
drm_clip_rect_t ** pClipRects,
|
2012-06-10 07:21:05 -06:00
|
|
|
int *backX,
|
|
|
|
int *backY,
|
|
|
|
int *numBackClipRects, drm_clip_rect_t ** pBackClipRects)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv, pOldDrawPriv;
|
|
|
|
WindowPtr pWin, pOldWin;
|
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#if 0
|
2012-06-10 07:21:05 -06:00
|
|
|
printf("maxDrawableTableEntry = %d\n",
|
|
|
|
pDRIPriv->pDriverInfo->maxDrawableTableEntry);
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (pDrawable->type == DRAWABLE_WINDOW) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pWin = (WindowPtr) pDrawable;
|
|
|
|
if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
|
|
|
|
|
|
|
|
/* Manage drawable table */
|
|
|
|
if (pDRIDrawablePriv->drawableIndex == -1) { /* load SAREA table */
|
|
|
|
|
|
|
|
/* Search table for empty entry */
|
|
|
|
i = 0;
|
|
|
|
while (i < pDRIPriv->pDriverInfo->maxDrawableTableEntry) {
|
|
|
|
if (!(pDRIPriv->DRIDrawables[i])) {
|
|
|
|
pDRIPriv->DRIDrawables[i] = pDrawable;
|
|
|
|
pDRIDrawablePriv->drawableIndex = i;
|
|
|
|
pDRIPriv->pSAREA->drawableTable[i].stamp =
|
|
|
|
DRIDrawableValidationStamp++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search table for oldest entry */
|
|
|
|
if (i == pDRIPriv->pDriverInfo->maxDrawableTableEntry) {
|
2006-11-26 11:13:41 -07:00
|
|
|
unsigned int oldestStamp = ~0;
|
|
|
|
int oldestIndex = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
i = pDRIPriv->pDriverInfo->maxDrawableTableEntry;
|
|
|
|
while (i--) {
|
|
|
|
if (pDRIPriv->pSAREA->drawableTable[i].stamp <
|
|
|
|
oldestStamp) {
|
|
|
|
oldestIndex = i;
|
|
|
|
oldestStamp =
|
|
|
|
pDRIPriv->pSAREA->drawableTable[i].stamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pDRIDrawablePriv->drawableIndex = oldestIndex;
|
|
|
|
|
|
|
|
/* release oldest drawable table entry */
|
|
|
|
pOldWin = (WindowPtr) pDRIPriv->DRIDrawables[oldestIndex];
|
|
|
|
pOldDrawPriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pOldWin);
|
|
|
|
pOldDrawPriv->drawableIndex = -1;
|
|
|
|
|
|
|
|
/* claim drawable table entry */
|
|
|
|
pDRIPriv->DRIDrawables[oldestIndex] = pDrawable;
|
|
|
|
|
|
|
|
/* validate SAREA entry */
|
|
|
|
pDRIPriv->pSAREA->drawableTable[oldestIndex].stamp =
|
|
|
|
DRIDrawableValidationStamp++;
|
|
|
|
|
|
|
|
/* check for stamp wrap around */
|
|
|
|
if (oldestStamp > DRIDrawableValidationStamp) {
|
|
|
|
|
|
|
|
/* walk SAREA table and invalidate all drawables */
|
|
|
|
for (i = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
i < pDRIPriv->pDriverInfo->maxDrawableTableEntry;
|
|
|
|
i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->pSAREA->drawableTable[i].stamp =
|
|
|
|
DRIDrawableValidationStamp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the driver wants to be notified when the index is
|
|
|
|
* set for a drawable, let it know now.
|
|
|
|
*/
|
|
|
|
if (pDRIPriv->pDriverInfo->SetDrawableIndex)
|
|
|
|
pDRIPriv->pDriverInfo->SetDrawableIndex(pWin,
|
|
|
|
pDRIDrawablePriv->
|
|
|
|
drawableIndex);
|
|
|
|
|
|
|
|
/* reinit drawable ID if window is visible */
|
|
|
|
if ((pWin->viewable) &&
|
|
|
|
(pDRIPriv->pDriverInfo->bufferRequests != DRI_NO_WINDOWS)) {
|
|
|
|
(*pDRIPriv->pDriverInfo->InitBuffers) (pWin,
|
|
|
|
&pWin->clipList,
|
|
|
|
pDRIDrawablePriv->
|
|
|
|
drawableIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*index = pDRIDrawablePriv->drawableIndex;
|
|
|
|
*stamp = pDRIPriv->pSAREA->drawableTable[*index].stamp;
|
|
|
|
*X = (int) (pWin->drawable.x);
|
|
|
|
*Y = (int) (pWin->drawable.y);
|
|
|
|
*W = (int) (pWin->drawable.width);
|
|
|
|
*H = (int) (pWin->drawable.height);
|
|
|
|
*numClipRects = RegionNumRects(&pWin->clipList);
|
|
|
|
*pClipRects = (drm_clip_rect_t *) RegionRects(&pWin->clipList);
|
|
|
|
|
|
|
|
if (!*numClipRects && pDRIPriv->fullscreen) {
|
|
|
|
/* use fake full-screen clip rect */
|
|
|
|
pDRIPriv->fullscreen_rect.x1 = *X;
|
|
|
|
pDRIPriv->fullscreen_rect.y1 = *Y;
|
|
|
|
pDRIPriv->fullscreen_rect.x2 = *X + *W;
|
|
|
|
pDRIPriv->fullscreen_rect.y2 = *Y + *H;
|
|
|
|
|
|
|
|
*numClipRects = 1;
|
|
|
|
*pClipRects = &pDRIPriv->fullscreen_rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
*backX = *X;
|
|
|
|
*backY = *Y;
|
|
|
|
|
|
|
|
if (pDRIPriv->nrWindowsVisible == 1 && *numClipRects) {
|
|
|
|
/* Use a single cliprect. */
|
|
|
|
|
|
|
|
int x0 = *X;
|
|
|
|
int y0 = *Y;
|
|
|
|
int x1 = x0 + *W;
|
|
|
|
int y1 = y0 + *H;
|
|
|
|
|
|
|
|
if (x0 < 0)
|
|
|
|
x0 = 0;
|
|
|
|
if (y0 < 0)
|
|
|
|
y0 = 0;
|
|
|
|
if (x1 > pScreen->width)
|
|
|
|
x1 = pScreen->width;
|
|
|
|
if (y1 > pScreen->height)
|
|
|
|
y1 = pScreen->height;
|
|
|
|
|
|
|
|
if (y0 >= y1 || x0 >= x1) {
|
|
|
|
*numBackClipRects = 0;
|
|
|
|
*pBackClipRects = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pDRIPriv->private_buffer_rect.x1 = x0;
|
|
|
|
pDRIPriv->private_buffer_rect.y1 = y0;
|
|
|
|
pDRIPriv->private_buffer_rect.x2 = x1;
|
|
|
|
pDRIPriv->private_buffer_rect.y2 = y1;
|
|
|
|
|
|
|
|
*numBackClipRects = 1;
|
|
|
|
*pBackClipRects = &(pDRIPriv->private_buffer_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Use the frontbuffer cliprects for back buffers. */
|
|
|
|
*numBackClipRects = 0;
|
|
|
|
*pBackClipRects = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Not a DRIDrawable */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* pixmap (or for GLX 1.3, a PBuffer) */
|
|
|
|
/* NOT_DONE */
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bool
|
|
|
|
DRIGetDeviceInfo(ScreenPtr pScreen,
|
|
|
|
drm_handle_t * hFrameBuffer,
|
2012-06-10 07:21:05 -06:00
|
|
|
int *fbOrigin,
|
|
|
|
int *fbSize,
|
|
|
|
int *fbStride, int *devPrivateSize, void **pDevPrivate)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
*hFrameBuffer = pDRIPriv->pDriverInfo->hFrameBuffer;
|
2006-11-26 11:13:41 -07:00
|
|
|
*fbOrigin = 0;
|
|
|
|
*fbSize = pDRIPriv->pDriverInfo->frameBufferSize;
|
|
|
|
*fbStride = pDRIPriv->pDriverInfo->frameBufferStride;
|
|
|
|
*devPrivateSize = pDRIPriv->pDriverInfo->devPrivateSize;
|
|
|
|
*pDevPrivate = pDRIPriv->pDriverInfo->devPrivate;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
DRIInfoPtr
|
|
|
|
DRICreateInfoRec(void)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIInfoPtr inforec = (DRIInfoPtr) calloc(1, sizeof(DRIInfoRec));
|
|
|
|
|
|
|
|
if (!inforec)
|
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Initialize defaults */
|
|
|
|
inforec->busIdString = NULL;
|
|
|
|
|
|
|
|
/* Wrapped function defaults */
|
2012-06-10 07:21:05 -06:00
|
|
|
inforec->wrap.WakeupHandler = DRIDoWakeupHandler;
|
|
|
|
inforec->wrap.BlockHandler = DRIDoBlockHandler;
|
|
|
|
inforec->wrap.WindowExposures = DRIWindowExposures;
|
|
|
|
inforec->wrap.CopyWindow = DRICopyWindow;
|
|
|
|
inforec->wrap.ValidateTree = DRIValidateTree;
|
|
|
|
inforec->wrap.PostValidateTree = DRIPostValidateTree;
|
|
|
|
inforec->wrap.ClipNotify = DRIClipNotify;
|
|
|
|
inforec->wrap.AdjustFrame = DRIAdjustFrame;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
inforec->TransitionTo2d = 0;
|
|
|
|
inforec->TransitionTo3d = 0;
|
|
|
|
inforec->SetDrawableIndex = 0;
|
|
|
|
|
|
|
|
return inforec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIDestroyInfoRec(DRIInfoPtr DRIInfo)
|
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
free(DRIInfo->busIdString);
|
2012-06-10 07:21:05 -06:00
|
|
|
free((char *) DRIInfo);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIWakeupHandler(pointer wakeupData, int result, pointer pReadmask)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ScreenPtr pScreen = screenInfo.screens[i];
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.WakeupHandler)
|
|
|
|
(*pDRIPriv->pDriverInfo->wrap.WakeupHandler) (i, wakeupData,
|
|
|
|
result, pReadmask);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadmask)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
ScreenPtr pScreen = screenInfo.screens[i];
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv && pDRIPriv->pDriverInfo->wrap.BlockHandler)
|
|
|
|
(*pDRIPriv->pDriverInfo->wrap.BlockHandler) (i, blockData,
|
|
|
|
pTimeout, pReadmask);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIDoWakeupHandler(int screenNum, pointer wakeupData,
|
|
|
|
unsigned long result, pointer pReadmask)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = screenInfo.screens[screenNum];
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
DRILock(pScreen, 0);
|
|
|
|
if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* hide X context by swapping 2D component here */
|
|
|
|
(*pDRIPriv->pDriverInfo->SwapContext) (pScreen,
|
|
|
|
DRI_3D_SYNC,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->partial3DContextStore,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->hiddenContextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIDoBlockHandler(int screenNum, pointer blockData,
|
|
|
|
pointer pTimeout, pointer pReadmask)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = screenInfo.screens[screenNum];
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
|
|
|
if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* hide X context by swapping 2D component here */
|
|
|
|
(*pDRIPriv->pDriverInfo->SwapContext) (pScreen,
|
|
|
|
DRI_2D_SYNC,
|
|
|
|
DRI_NO_CONTEXT,
|
|
|
|
NULL,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->partial3DContextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pDRIPriv->windowsTouched)
|
|
|
|
DRM_SPINUNLOCK(&pDRIPriv->pSAREA->drawable_lock, 1);
|
|
|
|
pDRIPriv->windowsTouched = FALSE;
|
|
|
|
|
|
|
|
DRIUnlock(pScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRISwapContext(int drmFD, void *oldctx, void *newctx)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIContextPrivPtr oldContext = (DRIContextPrivPtr) oldctx;
|
|
|
|
DRIContextPrivPtr newContext = (DRIContextPrivPtr) newctx;
|
|
|
|
ScreenPtr pScreen = newContext->pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
void *oldContextStore = NULL;
|
|
|
|
DRIContextType oldContextType;
|
|
|
|
void *newContextStore = NULL;
|
|
|
|
DRIContextType newContextType;
|
|
|
|
DRISyncType syncType;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef DEBUG
|
2012-06-10 07:21:05 -06:00
|
|
|
static int count = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (!newContext) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[DRI] Context Switch Error: oldContext=%x, newContext=%x\n",
|
|
|
|
oldContext, newContext);
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* usefull for debugging, just print out after n context switches */
|
|
|
|
if (!count || !(count % 1)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[DRI] Context switch %5d from %p/0x%08x (%d)\n",
|
|
|
|
count,
|
|
|
|
oldContext,
|
|
|
|
oldContext ? oldContext->flags : 0,
|
|
|
|
oldContext ? oldContext->hwContext : -1);
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_INFO,
|
|
|
|
"[DRI] Context switch %5d to %p/0x%08x (%d)\n",
|
|
|
|
count,
|
|
|
|
newContext,
|
|
|
|
newContext ? newContext->flags : 0,
|
|
|
|
newContext ? newContext->hwContext : -1);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
++count;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!pDRIPriv->pDriverInfo->SwapContext) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[DRI] DDX driver missing context swap call back\n");
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) {
|
|
|
|
|
|
|
|
/* only 3D contexts are swapped in this case */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (oldContext) {
|
|
|
|
oldContextStore = DRIGetContextStore(oldContext);
|
|
|
|
oldContext->valid3D = TRUE;
|
|
|
|
oldContextType = DRI_3D_CONTEXT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
oldContextType = DRI_NO_CONTEXT;
|
|
|
|
}
|
|
|
|
newContextStore = DRIGetContextStore(newContext);
|
|
|
|
if ((newContext->valid3D) &&
|
|
|
|
(newContext->hwContext != pDRIPriv->myContext)) {
|
|
|
|
newContextType = DRI_3D_CONTEXT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newContextType = DRI_2D_CONTEXT;
|
|
|
|
}
|
|
|
|
syncType = DRI_3D_SYNC;
|
|
|
|
}
|
|
|
|
else { /* default: driverSwapMethod == DRI_SERVER_SWAP */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* optimize 2D context swaps */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (newContext->flags & DRI_CONTEXT_2DONLY) {
|
|
|
|
/* go from 3D context to 2D context and only save 2D
|
2006-11-26 11:13:41 -07:00
|
|
|
* subset of 3D state
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
oldContextStore = DRIGetContextStore(oldContext);
|
|
|
|
oldContextType = DRI_2D_CONTEXT;
|
|
|
|
newContextStore = DRIGetContextStore(newContext);
|
|
|
|
newContextType = DRI_2D_CONTEXT;
|
|
|
|
syncType = DRI_3D_SYNC;
|
|
|
|
pDRIPriv->lastPartial3DContext = oldContext;
|
|
|
|
}
|
|
|
|
else if (oldContext->flags & DRI_CONTEXT_2DONLY) {
|
|
|
|
if (pDRIPriv->lastPartial3DContext == newContext) {
|
|
|
|
/* go from 2D context back to previous 3D context and
|
|
|
|
* only restore 2D subset of previous 3D state
|
|
|
|
*/
|
|
|
|
oldContextStore = DRIGetContextStore(oldContext);
|
|
|
|
oldContextType = DRI_2D_CONTEXT;
|
|
|
|
newContextStore = DRIGetContextStore(newContext);
|
|
|
|
newContextType = DRI_2D_CONTEXT;
|
|
|
|
syncType = DRI_2D_SYNC;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* go from 2D context to a different 3D context */
|
|
|
|
|
|
|
|
/* call DDX driver to do partial restore */
|
|
|
|
oldContextStore = DRIGetContextStore(oldContext);
|
|
|
|
newContextStore =
|
|
|
|
DRIGetContextStore(pDRIPriv->lastPartial3DContext);
|
|
|
|
(*pDRIPriv->pDriverInfo->SwapContext) (pScreen,
|
|
|
|
DRI_2D_SYNC,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
oldContextStore,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
newContextStore);
|
|
|
|
|
|
|
|
/* now setup for a complete 3D swap */
|
|
|
|
oldContextStore = newContextStore;
|
|
|
|
oldContext->valid3D = TRUE;
|
|
|
|
oldContextType = DRI_3D_CONTEXT;
|
|
|
|
newContextStore = DRIGetContextStore(newContext);
|
|
|
|
if ((newContext->valid3D) &&
|
|
|
|
(newContext->hwContext != pDRIPriv->myContext)) {
|
|
|
|
newContextType = DRI_3D_CONTEXT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newContextType = DRI_2D_CONTEXT;
|
|
|
|
}
|
|
|
|
syncType = DRI_NO_SYNC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* now setup for a complete 3D swap */
|
|
|
|
oldContextStore = newContextStore;
|
|
|
|
oldContext->valid3D = TRUE;
|
|
|
|
oldContextType = DRI_3D_CONTEXT;
|
|
|
|
newContextStore = DRIGetContextStore(newContext);
|
|
|
|
if ((newContext->valid3D) &&
|
|
|
|
(newContext->hwContext != pDRIPriv->myContext)) {
|
|
|
|
newContextType = DRI_3D_CONTEXT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newContextType = DRI_2D_CONTEXT;
|
|
|
|
}
|
|
|
|
syncType = DRI_3D_SYNC;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* call DDX driver to perform the swap */
|
2012-06-10 07:21:05 -06:00
|
|
|
(*pDRIPriv->pDriverInfo->SwapContext) (pScreen,
|
|
|
|
syncType,
|
|
|
|
oldContextType,
|
|
|
|
oldContextStore,
|
|
|
|
newContextType, newContextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
void *
|
2006-11-26 11:13:41 -07:00
|
|
|
DRIGetContextStore(DRIContextPrivPtr context)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
return ((void *) context->pContextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIDrawablePriv) {
|
|
|
|
(*pDRIPriv->pDriverInfo->InitBuffers) (pWin, prgn,
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIDrawablePriv->drawableIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* call lower wrapped functions */
|
|
|
|
if (pDRIPriv && pDRIPriv->wrap.WindowExposures) {
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* unwrap */
|
|
|
|
pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* call lower layers */
|
|
|
|
(*pScreen->WindowExposures) (pWin, prgn, bsreg);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* rewrap */
|
|
|
|
pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
|
|
|
|
pScreen->WindowExposures = DRIWindowExposures;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
DRITreeTraversal(WindowPtr pWin, pointer data)
|
|
|
|
{
|
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIDrawablePriv) {
|
2006-11-26 11:13:41 -07:00
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (RegionNumRects(&(pWin->clipList)) > 0) {
|
|
|
|
RegionPtr reg = (RegionPtr) data;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
RegionUnion(reg, reg, &(pWin->clipList));
|
|
|
|
pDRIPriv->nrWalked++;
|
|
|
|
}
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->nrWindows == pDRIPriv->nrWalked)
|
|
|
|
return WT_STOPWALKING;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return WT_WALKCHILDREN;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
Bool
|
|
|
|
DRIDestroyWindow(WindowPtr pWin)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
Bool retval = TRUE;
|
|
|
|
|
|
|
|
DRIDrawablePrivDestroy(pWin);
|
|
|
|
|
|
|
|
/* call lower wrapped functions */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->DestroyWindow) {
|
|
|
|
/* unwrap */
|
|
|
|
pScreen->DestroyWindow = pDRIPriv->DestroyWindow;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* call lower layers */
|
|
|
|
retval = (*pScreen->DestroyWindow) (pWin);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* rewrap */
|
|
|
|
pDRIPriv->DestroyWindow = pScreen->DestroyWindow;
|
|
|
|
pScreen->DestroyWindow = DRIDestroyWindow;
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
void
|
|
|
|
DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->nrWindowsVisible > 0) {
|
|
|
|
RegionRec reg;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
RegionNull(®);
|
|
|
|
pDRIPriv->nrWalked = 0;
|
|
|
|
TraverseTree(pWin, DRITreeTraversal, (pointer) (®));
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (RegionNotEmpty(®)) {
|
|
|
|
RegionTranslate(®, ptOldOrg.x - pWin->drawable.x,
|
|
|
|
ptOldOrg.y - pWin->drawable.y);
|
|
|
|
RegionIntersect(®, ®, prgnSrc);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* The MoveBuffers interface is not ideal */
|
|
|
|
(*pDRIPriv->pDriverInfo->MoveBuffers) (pWin, ptOldOrg, ®,
|
|
|
|
pDRIPriv->pDriverInfo->
|
|
|
|
ddxDrawableTableEntry);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
RegionUninit(®);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* call lower wrapped functions */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->wrap.CopyWindow) {
|
|
|
|
/* unwrap */
|
|
|
|
pScreen->CopyWindow = pDRIPriv->wrap.CopyWindow;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* call lower layers */
|
|
|
|
(*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* rewrap */
|
|
|
|
pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
|
|
|
|
pScreen->CopyWindow = DRICopyWindow;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRIGetSecs(long *secs, long *usecs)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
*secs = tv.tv_sec;
|
2006-11-26 11:13:41 -07:00
|
|
|
*usecs = tv.tv_usec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long
|
|
|
|
DRIComputeMilliSeconds(unsigned long s_secs, unsigned long s_usecs,
|
2012-06-10 07:21:05 -06:00
|
|
|
unsigned long f_secs, unsigned long f_usecs)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
if (f_usecs < s_usecs) {
|
2012-06-10 07:21:05 -06:00
|
|
|
--f_secs;
|
|
|
|
f_usecs += 1000000;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return (f_secs - s_secs) * 1000 + (f_usecs - s_usecs) / 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
DRISpinLockTimeout(drmLock * lock, int val, unsigned long timeout /* in mS */ )
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int count = 10000;
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#if !defined(__alpha__) && !defined(__powerpc__)
|
|
|
|
char ret;
|
|
|
|
#else
|
|
|
|
int ret;
|
|
|
|
#endif
|
|
|
|
long s_secs, s_usecs;
|
|
|
|
long f_secs, f_usecs;
|
|
|
|
long msecs;
|
2012-06-10 07:21:05 -06:00
|
|
|
long prev = 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
DRIGetSecs(&s_secs, &s_usecs);
|
|
|
|
|
|
|
|
do {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRM_SPINLOCK_COUNT(lock, val, count, ret);
|
|
|
|
if (!ret)
|
|
|
|
return; /* Got lock */
|
|
|
|
DRIGetSecs(&f_secs, &f_usecs);
|
|
|
|
msecs = DRIComputeMilliSeconds(s_secs, s_usecs, f_secs, f_usecs);
|
|
|
|
if (msecs - prev < 250)
|
|
|
|
count *= 2; /* Not more than 0.5S */
|
2006-11-26 11:13:41 -07:00
|
|
|
} while (msecs < timeout);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Didn't get lock, so take it. The worst
|
|
|
|
that can happen is that there is some
|
|
|
|
garbage written to the wrong part of the
|
|
|
|
framebuffer that a refresh will repair.
|
|
|
|
That's undesirable, but better than
|
|
|
|
locking the server. This should be a
|
|
|
|
very rare event. */
|
2006-11-26 11:13:41 -07:00
|
|
|
DRM_SPINLOCK_TAKE(lock, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRILockTree(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Restore the last known 3D context if the X context is hidden */
|
|
|
|
if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) {
|
2012-06-10 07:21:05 -06:00
|
|
|
(*pDRIPriv->pDriverInfo->SwapContext) (pScreen,
|
|
|
|
DRI_2D_SYNC,
|
|
|
|
DRI_NO_CONTEXT,
|
|
|
|
NULL,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->partial3DContextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Call kernel to release lock */
|
|
|
|
DRIUnlock(pScreen);
|
|
|
|
|
|
|
|
/* Grab drawable spin lock: a time out between 10 and 30 seconds is
|
|
|
|
appropriate, since this should never time out except in the case of
|
|
|
|
client death while the lock is being held. The timeout must be
|
|
|
|
greater than any reasonable rendering time. */
|
2012-06-10 07:21:05 -06:00
|
|
|
DRISpinLockTimeout(&pDRIPriv->pSAREA->drawable_lock, 1, 10000); /*10 secs */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Call kernel flush outstanding buffers and relock */
|
2012-06-10 07:21:05 -06:00
|
|
|
DRILock(pScreen, DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH_ALL);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Switch back to our 2D context if the X context is hidden */
|
|
|
|
if (pDRIPriv->pDriverInfo->driverSwapMethod == DRI_HIDE_X_CONTEXT) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* hide X context by swapping 2D component here */
|
|
|
|
(*pDRIPriv->pDriverInfo->SwapContext) (pScreen,
|
|
|
|
DRI_3D_SYNC,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->partial3DContextStore,
|
|
|
|
DRI_2D_CONTEXT,
|
|
|
|
pDRIPriv->hiddenContextStore);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pParent->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
int returnValue = 1; /* always return 1, not checked by dix/window.c */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv)
|
|
|
|
return returnValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* call lower wrapped functions */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->wrap.ValidateTree) {
|
|
|
|
/* unwrap */
|
|
|
|
pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* call lower layers */
|
|
|
|
returnValue = (*pScreen->ValidateTree) (pParent, pChild, kind);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* rewrap */
|
|
|
|
pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
|
|
|
|
pScreen->ValidateTree = DRIValidateTree;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv;
|
|
|
|
|
|
|
|
if (pParent) {
|
2012-06-10 07:21:05 -06:00
|
|
|
pScreen = pParent->drawable.pScreen;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
|
|
|
pScreen = pChild->drawable.pScreen;
|
|
|
|
}
|
|
|
|
if (!(pDRIPriv = DRI_SCREEN_PRIV(pScreen)))
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (pDRIPriv->wrap.PostValidateTree) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* unwrap */
|
|
|
|
pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* call lower layers */
|
|
|
|
(*pScreen->PostValidateTree) (pParent, pChild, kind);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* rewrap */
|
|
|
|
pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
|
|
|
|
pScreen->PostValidateTree = DRIPostValidateTree;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIClipNotify(WindowPtr pWin, int dx, int dy)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv)
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if ((pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin))) {
|
2010-12-05 08:36:02 -07:00
|
|
|
int nrects = RegionNumRects(&pWin->clipList);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv->windowsTouched) {
|
2006-11-26 11:13:41 -07:00
|
|
|
DRILockTree(pScreen);
|
|
|
|
pDRIPriv->windowsTouched = TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (nrects && !pDRIDrawablePriv->nrects)
|
|
|
|
DRIIncreaseNumberVisible(pScreen);
|
|
|
|
else if (!nrects && pDRIDrawablePriv->nrects)
|
|
|
|
DRIDecreaseNumberVisible(pScreen);
|
|
|
|
else
|
|
|
|
DRIDriverClipNotify(pScreen);
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIDrawablePriv->nrects = nrects;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->pSAREA->drawableTable[pDRIDrawablePriv->drawableIndex].stamp
|
|
|
|
= DRIDrawableValidationStamp++;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
drmUpdateDrawableInfo(pDRIPriv->drmFD, pDRIDrawablePriv->hwDrawable,
|
|
|
|
DRM_DRAWABLE_CLIPRECTS,
|
|
|
|
nrects, RegionRects(&pWin->clipList));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* call lower wrapped functions */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->wrap.ClipNotify) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* unwrap */
|
2006-11-26 11:13:41 -07:00
|
|
|
pScreen->ClipNotify = pDRIPriv->wrap.ClipNotify;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* call lower layers */
|
|
|
|
(*pScreen->ClipNotify) (pWin, dx, dy);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
/* rewrap */
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIPriv->wrap.ClipNotify = pScreen->ClipNotify;
|
|
|
|
pScreen->ClipNotify = DRIClipNotify;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CARD32
|
|
|
|
DRIGetDrawableIndex(WindowPtr pWin)
|
|
|
|
{
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
|
|
|
|
CARD32 index;
|
|
|
|
|
|
|
|
if (pDRIDrawablePriv) {
|
2012-06-10 07:21:05 -06:00
|
|
|
index = pDRIDrawablePriv->drawableIndex;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-06-10 07:21:05 -06:00
|
|
|
index = pDRIPriv->pDriverInfo->ddxDrawableTableEntry;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
|
|
|
DRIGetDrawableStamp(ScreenPtr pScreen, CARD32 drawable_index)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
return pDRIPriv->pSAREA->drawableTable[drawable_index].stamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIPrintDrawableLock(ScreenPtr pScreen, char *msg)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
ErrorF("%s: %d\n", msg, pDRIPriv->pSAREA->drawable_lock.lock);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRILock(ScreenPtr pScreen, int flags)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv || !pDRIPriv->pLockRefCount)
|
|
|
|
return;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
if (!*pDRIPriv->pLockRefCount) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRM_LOCK(pDRIPriv->drmFD, pDRIPriv->pLSAREA, pDRIPriv->myContext,
|
|
|
|
flags);
|
|
|
|
*pDRIPriv->pLockingContext = pDRIPriv->myContext;
|
|
|
|
}
|
|
|
|
else if (*pDRIPriv->pLockingContext != pDRIPriv->myContext) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[DRI] Locking deadlock.\n"
|
|
|
|
"\tAlready locked with context %d,\n"
|
|
|
|
"\ttrying to lock with context %d.\n",
|
|
|
|
pDRIPriv->pLockingContext, pDRIPriv->myContext);
|
2007-11-24 10:55:21 -07:00
|
|
|
}
|
|
|
|
(*pDRIPriv->pLockRefCount)++;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIUnlock(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv || !pDRIPriv->pLockRefCount)
|
|
|
|
return;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
|
|
|
if (*pDRIPriv->pLockRefCount > 0) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pDRIPriv->myContext != *pDRIPriv->pLockingContext) {
|
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
|
|
|
"[DRI] Unlocking inconsistency:\n"
|
|
|
|
"\tContext %d trying to unlock lock held by context %d\n",
|
|
|
|
pDRIPriv->pLockingContext, pDRIPriv->myContext);
|
|
|
|
}
|
|
|
|
(*pDRIPriv->pLockRefCount)--;
|
|
|
|
}
|
|
|
|
else {
|
2007-11-24 10:55:21 -07:00
|
|
|
DRIDrvMsg(pScreen->myNum, X_ERROR,
|
2012-06-10 07:21:05 -06:00
|
|
|
"DRIUnlock called when not locked.\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!*pDRIPriv->pLockRefCount)
|
2007-11-24 10:55:21 -07:00
|
|
|
DRM_UNLOCK(pDRIPriv->drmFD, pDRIPriv->pLSAREA, pDRIPriv->myContext);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
DRIGetSAREAPrivate(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return (void *) (((char *) pDRIPriv->pSAREA) + sizeof(XF86DRISAREARec));
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
drm_context_t
|
|
|
|
DRIGetContext(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (!pDRIPriv)
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return pDRIPriv->myContext;
|
|
|
|
}
|
|
|
|
|
2007-11-24 10:55:21 -07:00
|
|
|
void
|
|
|
|
DRIGetTexOffsetFuncs(ScreenPtr pScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
DRITexOffsetStartProcPtr * texOffsetStartFunc,
|
|
|
|
DRITexOffsetFinishProcPtr * texOffsetFinishFunc)
|
2007-11-24 10:55:21 -07:00
|
|
|
{
|
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pDRIPriv)
|
|
|
|
return;
|
2007-11-24 10:55:21 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
*texOffsetStartFunc = pDRIPriv->pDriverInfo->texOffsetStart;
|
2007-11-24 10:55:21 -07:00
|
|
|
*texOffsetFinishFunc = pDRIPriv->pDriverInfo->texOffsetFinish;
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
/* This lets get at the unwrapped functions so that they can correctly
|
|
|
|
* call the lowerlevel functions, and choose whether they will be
|
|
|
|
* called at every level of recursion (eg in validatetree).
|
|
|
|
*/
|
|
|
|
DRIWrappedFuncsRec *
|
|
|
|
DRIGetWrappedFuncs(ScreenPtr pScreen)
|
|
|
|
{
|
|
|
|
return &(DRI_SCREEN_PRIV(pScreen)->wrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* note that this returns the library version, not the protocol version */
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIQueryVersion(int *majorVersion, int *minorVersion, int *patchVersion)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
*majorVersion = DRIINFO_MAJOR_VERSION;
|
|
|
|
*minorVersion = DRIINFO_MINOR_VERSION;
|
|
|
|
*patchVersion = DRIINFO_PATCH_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_DRIAdjustFrame(ScrnInfoPtr pScrn, DRIScreenPrivPtr pDRIPriv, int x, int y)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
pDRIPriv->pSAREA->frame.x = x;
|
|
|
|
pDRIPriv->pSAREA->frame.y = y;
|
|
|
|
pDRIPriv->pSAREA->frame.width = pScrn->frameX1 - x + 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
pDRIPriv->pSAREA->frame.height = pScrn->frameY1 - y + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DRIAdjustFrame(int scrnIndex, int x, int y, int flags)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
ScreenPtr pScreen = screenInfo.screens[scrnIndex];
|
2006-11-26 11:13:41 -07:00
|
|
|
DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
|
|
|
|
int px, py;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (!pDRIPriv || !pDRIPriv->pSAREA) {
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIDrvMsg(scrnIndex, X_ERROR, "[DRI] No SAREA (%p %p)\n",
|
|
|
|
pDRIPriv, pDRIPriv ? pDRIPriv->pSAREA : NULL);
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pDRIPriv->fullscreen) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* Fix up frame */
|
|
|
|
pScrn->frameX0 = pDRIPriv->pSAREA->frame.x;
|
|
|
|
pScrn->frameY0 = pDRIPriv->pSAREA->frame.y;
|
|
|
|
pScrn->frameX1 = pScrn->frameX0 + pDRIPriv->pSAREA->frame.width - 1;
|
|
|
|
pScrn->frameY1 = pScrn->frameY0 + pDRIPriv->pSAREA->frame.height - 1;
|
|
|
|
|
|
|
|
/* Fix up cursor */
|
|
|
|
miPointerGetPosition(inputInfo.pointer, &px, &py);
|
|
|
|
|
|
|
|
if (px < pScrn->frameX0)
|
|
|
|
px = pScrn->frameX0;
|
|
|
|
if (px > pScrn->frameX1)
|
|
|
|
px = pScrn->frameX1;
|
|
|
|
if (py < pScrn->frameY0)
|
|
|
|
py = pScrn->frameY0;
|
|
|
|
if (py > pScrn->frameY1)
|
|
|
|
py = pScrn->frameY1;
|
|
|
|
pScreen->SetCursorPosition(inputInfo.pointer, pScreen, px, py, TRUE);
|
|
|
|
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pDRIPriv->wrap.AdjustFrame) {
|
2012-06-10 07:21:05 -06:00
|
|
|
/* unwrap */
|
|
|
|
pScrn->AdjustFrame = pDRIPriv->wrap.AdjustFrame;
|
|
|
|
/* call lower layers */
|
|
|
|
(*pScrn->AdjustFrame) (scrnIndex, x, y, flags);
|
|
|
|
/* rewrap */
|
|
|
|
pDRIPriv->wrap.AdjustFrame = pScrn->AdjustFrame;
|
|
|
|
pScrn->AdjustFrame = DRIAdjustFrame;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_DRIAdjustFrame(pScrn, pDRIPriv, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DRIMoveBuffersHelper swaps the regions rects in place leaving you
|
|
|
|
* a region with the rects in the order that you need to blit them,
|
|
|
|
* but it is possibly (likely) an invalid region afterwards. If you
|
|
|
|
* need to use the region again for anything you have to call
|
|
|
|
* REGION_VALIDATE on it, or better yet, save a copy first.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
DRIMoveBuffersHelper(ScreenPtr pScreen,
|
|
|
|
int dx, int dy, int *xdir, int *ydir, RegionPtr reg)
|
|
|
|
{
|
|
|
|
BoxPtr extents, pbox, firstBox, lastBox;
|
|
|
|
BoxRec tmpBox;
|
|
|
|
int y, nbox;
|
|
|
|
|
|
|
|
extents = RegionExtents(reg);
|
|
|
|
nbox = RegionNumRects(reg);
|
|
|
|
pbox = RegionRects(reg);
|
|
|
|
|
|
|
|
if ((dy > 0) && (dy < (extents->y2 - extents->y1))) {
|
|
|
|
*ydir = -1;
|
|
|
|
if (nbox > 1) {
|
|
|
|
firstBox = pbox;
|
|
|
|
lastBox = pbox + nbox - 1;
|
|
|
|
while ((unsigned long) firstBox < (unsigned long) lastBox) {
|
|
|
|
tmpBox = *firstBox;
|
|
|
|
*firstBox = *lastBox;
|
|
|
|
*lastBox = tmpBox;
|
|
|
|
firstBox++;
|
|
|
|
lastBox--;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*ydir = 1;
|
|
|
|
|
|
|
|
if ((dx > 0) && (dx < (extents->x2 - extents->x1))) {
|
|
|
|
*xdir = -1;
|
|
|
|
if (nbox > 1) {
|
|
|
|
firstBox = lastBox = pbox;
|
|
|
|
y = pbox->y1;
|
|
|
|
while (--nbox) {
|
|
|
|
pbox++;
|
|
|
|
if (pbox->y1 == y)
|
|
|
|
lastBox++;
|
|
|
|
else {
|
|
|
|
while ((unsigned long) firstBox < (unsigned long) lastBox) {
|
|
|
|
tmpBox = *firstBox;
|
|
|
|
*firstBox = *lastBox;
|
|
|
|
*lastBox = tmpBox;
|
|
|
|
firstBox++;
|
|
|
|
lastBox--;
|
|
|
|
}
|
|
|
|
|
|
|
|
firstBox = lastBox = pbox;
|
|
|
|
y = pbox->y1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((unsigned long) firstBox < (unsigned long) lastBox) {
|
|
|
|
tmpBox = *firstBox;
|
|
|
|
*firstBox = *lastBox;
|
|
|
|
*lastBox = tmpBox;
|
|
|
|
firstBox++;
|
|
|
|
lastBox--;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*xdir = 1;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2012-06-10 07:21:05 -06:00
|
|
|
DRICreatePCIBusID(const struct pci_device *dev)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
char *busID;
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (asprintf(&busID, "pci:%04x:%02x:%02x.%d",
|
2012-06-10 07:21:05 -06:00
|
|
|
dev->domain, dev->bus, dev->dev, dev->func) == -1)
|
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
return busID;
|
|
|
|
}
|