102be438aSmrg
202be438aSmrg#ifdef HAVE_CONFIG_H
302be438aSmrg#include "config.h"
402be438aSmrg#endif
502be438aSmrg
602be438aSmrg#include "xf86.h"
702be438aSmrg#include "xf86_OSproc.h"
802be438aSmrg#include "xf86Pci.h"
902be438aSmrg#include "fb.h"
1002be438aSmrg#include "miline.h"
1102be438aSmrg#include "tdfx.h"
1202be438aSmrg#include "tdfx_dri.h"
1302be438aSmrg#include "tdfx_dripriv.h"
1402be438aSmrg
1502be438aSmrgstatic char TDFXKernelDriverName[] = "tdfx";
1602be438aSmrgstatic char TDFXClientDriverName[] = "tdfx";
1702be438aSmrg
1802be438aSmrgstatic Bool TDFXCreateContext(ScreenPtr pScreen, VisualPtr visual,
1902be438aSmrg			      drm_context_t hwContext, void *pVisualConfigPriv,
2002be438aSmrg			      DRIContextType contextStore);
2102be438aSmrgstatic void TDFXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
2202be438aSmrg			       DRIContextType contextStore);
2302be438aSmrgstatic void TDFXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
2402be438aSmrg			       DRIContextType readContextType,
2502be438aSmrg			       void *readContextStore,
2602be438aSmrg			       DRIContextType writeContextType,
2702be438aSmrg			       void *writeContextStore);
2802be438aSmrgstatic Bool TDFXDRIOpenFullScreen(ScreenPtr pScreen);
2902be438aSmrgstatic Bool TDFXDRICloseFullScreen(ScreenPtr pScreen);
3002be438aSmrgstatic void TDFXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);
3102be438aSmrgstatic void TDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
3202be438aSmrg			       RegionPtr prgnSrc, CARD32 index);
3302be438aSmrgstatic void TDFXDRITransitionTo2d(ScreenPtr pScreen);
3402be438aSmrgstatic void TDFXDRITransitionTo3d(ScreenPtr pScreen);
3502be438aSmrg
3602be438aSmrgstatic void
373a56a767SmrgTDFXDoWakeupHandler(WAKEUPHANDLER_ARGS_DECL)
3802be438aSmrg{
393a56a767Smrg  SCREEN_PTR(arg);
403a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
4102be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
4202be438aSmrg
4302be438aSmrg  pTDFX->pDRIInfo->wrap.WakeupHandler = pTDFX->coreWakeupHandler;
443a56a767Smrg  (*pTDFX->pDRIInfo->wrap.WakeupHandler) (WAKEUPHANDLER_ARGS);
4502be438aSmrg  pTDFX->pDRIInfo->wrap.WakeupHandler = TDFXDoWakeupHandler;
4602be438aSmrg
4702be438aSmrg
4802be438aSmrg  TDFXNeedSync(pScrn);
4902be438aSmrg}
5002be438aSmrg
5102be438aSmrgstatic void
523a56a767SmrgTDFXDoBlockHandler(BLOCKHANDLER_ARGS_DECL)
5302be438aSmrg{
543a56a767Smrg  SCREEN_PTR(arg);
553a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
5602be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
5702be438aSmrg
5802be438aSmrg  TDFXCheckSync(pScrn);
5902be438aSmrg
6002be438aSmrg  pTDFX->pDRIInfo->wrap.BlockHandler = pTDFX->coreBlockHandler;
613a56a767Smrg  (*pTDFX->pDRIInfo->wrap.BlockHandler) (BLOCKHANDLER_ARGS);
6202be438aSmrg  pTDFX->pDRIInfo->wrap.BlockHandler = TDFXDoBlockHandler;
6302be438aSmrg
6402be438aSmrg}
6502be438aSmrg
6602be438aSmrgBool TDFXDRIScreenInit(ScreenPtr pScreen)
6702be438aSmrg{
683a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
6902be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
7002be438aSmrg  DRIInfoPtr pDRIInfo;
7102be438aSmrg  TDFXDRIPtr pTDFXDRI;
7202be438aSmrg  Bool bppOk = FALSE;
7302be438aSmrg
7402be438aSmrg  switch (pScrn->bitsPerPixel) {
7502be438aSmrg  case 16:
7602be438aSmrg    bppOk = TRUE;
7702be438aSmrg    break;
7802be438aSmrg  case 32:
7902be438aSmrg    if (pTDFX->ChipType > PCI_CHIP_VOODOO3) {
8002be438aSmrg      bppOk = TRUE;
8102be438aSmrg    }
8202be438aSmrg    break;
8302be438aSmrg  }
8402be438aSmrg  if (!bppOk) {
8502be438aSmrg    xf86DrvMsg(pScreen->myNum, X_ERROR,
8602be438aSmrg            "[dri] tdfx DRI not supported in %d bpp mode, disabling DRI.\n",
8702be438aSmrg            (pScrn->bitsPerPixel));
8802be438aSmrg    if (pTDFX->ChipType <= PCI_CHIP_VOODOO3) {
8902be438aSmrg      xf86DrvMsg(pScreen->myNum, X_INFO,
9002be438aSmrg              "[dri] To use DRI, invoke the server using 16 bpp\n"
9102be438aSmrg	      "\t(-depth 15 or -depth 16).\n");
9202be438aSmrg    } else {
9302be438aSmrg      xf86DrvMsg(pScreen->myNum, X_INFO,
9402be438aSmrg              "[dri] To use DRI, invoke the server using 16 bpp\n"
9502be438aSmrg	      "\t(-depth 15 or -depth 16) or 32 bpp (-depth 24 -fbbpp 32).\n");
9602be438aSmrg    }
9702be438aSmrg    return FALSE;
9802be438aSmrg  }
9902be438aSmrg
100daa73adaSmrg    /* Check that the DRI, and DRM modules have been loaded by testing
10102be438aSmrg       for canonical symbols in each module. */
10202be438aSmrg    if (!xf86LoaderCheckSymbol("drmAvailable"))        return FALSE;
10302be438aSmrg    if (!xf86LoaderCheckSymbol("DRIQueryVersion")) {
10402be438aSmrg      xf86DrvMsg(pScreen->myNum, X_ERROR,
10502be438aSmrg                 "TDFXDRIScreenInit failed (libdri.a too old)\n");
10602be438aSmrg      return FALSE;
10702be438aSmrg    }
10802be438aSmrg
10902be438aSmrg  /* Check the DRI version */
11002be438aSmrg  {
11102be438aSmrg    int major, minor, patch;
11202be438aSmrg    DRIQueryVersion(&major, &minor, &patch);
11302be438aSmrg    if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION) {
11402be438aSmrg      xf86DrvMsg(pScreen->myNum, X_ERROR,
11502be438aSmrg                 "[dri] TDFXDRIScreenInit failed because of a version mismatch.\n"
11602be438aSmrg                 "[dri] libdri version is %d.%d.%d but version %d.%d.x is needed.\n"
11702be438aSmrg                 "[dri] Disabling the DRI.\n",
11802be438aSmrg                 major, minor, patch,
11902be438aSmrg                 DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
12002be438aSmrg      return FALSE;
12102be438aSmrg    }
12202be438aSmrg  }
12302be438aSmrg
12402be438aSmrg  pDRIInfo = DRICreateInfoRec();
12502be438aSmrg  if (!pDRIInfo) {
12602be438aSmrg    xf86DrvMsg(pScreen->myNum, X_ERROR,
12702be438aSmrg               "[dri] DRICreateInfoRect() failed, disabling DRI.\n");
12802be438aSmrg    return FALSE;
12902be438aSmrg  }
13002be438aSmrg
13102be438aSmrg  pTDFX->pDRIInfo = pDRIInfo;
13202be438aSmrg
13302be438aSmrg  pDRIInfo->drmDriverName = TDFXKernelDriverName;
13402be438aSmrg  pDRIInfo->clientDriverName = TDFXClientDriverName;
135880ed95aSmrg#ifdef XSERVER_LIBPCIACCESS
136880ed95aSmrg    pDRIInfo->busIdString = DRICreatePCIBusID(pTDFX->PciInfo[0]);
137880ed95aSmrg#else
13802be438aSmrg  if (xf86LoaderCheckSymbol("DRICreatePCIBusID")) {
13902be438aSmrg    pDRIInfo->busIdString = DRICreatePCIBusID(pTDFX->PciInfo);
14002be438aSmrg  } else {
1413a56a767Smrg    pDRIInfo->busIdString = malloc(64);
14202be438aSmrg    sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
14302be438aSmrg	    ((pciConfigPtr)pTDFX->PciInfo->thisCard)->busnum,
14402be438aSmrg	    ((pciConfigPtr)pTDFX->PciInfo->thisCard)->devnum,
14502be438aSmrg	    ((pciConfigPtr)pTDFX->PciInfo->thisCard)->funcnum);
14602be438aSmrg  }
147880ed95aSmrg#endif
14802be438aSmrg  pDRIInfo->ddxDriverMajorVersion = TDFX_MAJOR_VERSION;
14902be438aSmrg  pDRIInfo->ddxDriverMinorVersion = TDFX_MINOR_VERSION;
15002be438aSmrg  pDRIInfo->ddxDriverPatchVersion = TDFX_PATCHLEVEL;
151c1d48fefSmrg  pDRIInfo->frameBufferPhysicalAddress = (pointer) pTDFX->LinearAddr[0];
15202be438aSmrg  pDRIInfo->frameBufferSize = pTDFX->FbMapSize;
15302be438aSmrg  pDRIInfo->frameBufferStride = pTDFX->stride;
15402be438aSmrg  pDRIInfo->ddxDrawableTableEntry = TDFX_MAX_DRAWABLES;
15502be438aSmrg
15602be438aSmrg  pTDFX->coreBlockHandler = pDRIInfo->wrap.BlockHandler;
15702be438aSmrg  pDRIInfo->wrap.BlockHandler = TDFXDoBlockHandler;
15802be438aSmrg  pTDFX->coreWakeupHandler = pDRIInfo->wrap.WakeupHandler;
15902be438aSmrg  pDRIInfo->wrap.WakeupHandler = TDFXDoWakeupHandler;
16002be438aSmrg
16102be438aSmrg  if (SAREA_MAX_DRAWABLES < TDFX_MAX_DRAWABLES)
16202be438aSmrg    pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES;
16302be438aSmrg  else
16402be438aSmrg    pDRIInfo->maxDrawableTableEntry = TDFX_MAX_DRAWABLES;
16502be438aSmrg
16602be438aSmrg#ifdef NOT_DONE
16702be438aSmrg  /* FIXME need to extend DRI protocol to pass this size back to client
16802be438aSmrg   * for SAREA mapping that includes a device private record
16902be438aSmrg   */
17002be438aSmrg  pDRIInfo->SAREASize =
17102be438aSmrg    ((sizeof(XF86DRISAREARec) + 0xfff) & 0x1000); /* round to page */
17202be438aSmrg  /* + shared memory device private rec */
17302be438aSmrg#else
17402be438aSmrg  /* For now the mapping works by using a fixed size defined
17502be438aSmrg   * in the SAREA header
17602be438aSmrg   */
17702be438aSmrg  if (sizeof(XF86DRISAREARec)+sizeof(TDFXSAREAPriv)>SAREA_MAX) {
17802be438aSmrg    xf86DrvMsg(pScreen->myNum, X_ERROR, "Data does not fit in SAREA\n");
17902be438aSmrg    return FALSE;
18002be438aSmrg  }
18102be438aSmrg  pDRIInfo->SAREASize = SAREA_MAX;
18202be438aSmrg#endif
18302be438aSmrg
1843a56a767Smrg  if (!(pTDFXDRI = (TDFXDRIPtr)calloc(sizeof(TDFXDRIRec),1))) {
18502be438aSmrg    xf86DrvMsg(pScreen->myNum, X_ERROR,
18602be438aSmrg               "[dri] DRI memory allocation failed, disabling DRI.\n");
18702be438aSmrg    DRIDestroyInfoRec(pTDFX->pDRIInfo);
18802be438aSmrg    pTDFX->pDRIInfo=0;
18902be438aSmrg    return FALSE;
19002be438aSmrg  }
19102be438aSmrg  pDRIInfo->devPrivate = pTDFXDRI;
19202be438aSmrg  pDRIInfo->devPrivateSize = sizeof(TDFXDRIRec);
19302be438aSmrg  pDRIInfo->contextSize = sizeof(TDFXDRIContextRec);
19402be438aSmrg
19502be438aSmrg  pDRIInfo->CreateContext = TDFXCreateContext;
19602be438aSmrg  pDRIInfo->DestroyContext = TDFXDestroyContext;
19702be438aSmrg  pDRIInfo->SwapContext = TDFXDRISwapContext;
19802be438aSmrg  pDRIInfo->InitBuffers = TDFXDRIInitBuffers;
19902be438aSmrg  pDRIInfo->MoveBuffers = TDFXDRIMoveBuffers;
20002be438aSmrg  pDRIInfo->OpenFullScreen = TDFXDRIOpenFullScreen;
20102be438aSmrg  pDRIInfo->CloseFullScreen = TDFXDRICloseFullScreen;
20202be438aSmrg  pDRIInfo->TransitionTo2d = TDFXDRITransitionTo2d;
20302be438aSmrg  pDRIInfo->TransitionTo3d = TDFXDRITransitionTo3d;
20402be438aSmrg  pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
20502be438aSmrg
20602be438aSmrg  pDRIInfo->createDummyCtx = FALSE;
20702be438aSmrg  pDRIInfo->createDummyCtxPriv = FALSE;
20802be438aSmrg
20902be438aSmrg  if (!DRIScreenInit(pScreen, pDRIInfo, &pTDFX->drmSubFD)) {
2103a56a767Smrg    free(pDRIInfo->devPrivate);
21102be438aSmrg    pDRIInfo->devPrivate=0;
21202be438aSmrg    DRIDestroyInfoRec(pTDFX->pDRIInfo);
21302be438aSmrg    pTDFX->pDRIInfo=0;
21402be438aSmrg    xf86DrvMsg(pScreen->myNum, X_ERROR,
21502be438aSmrg               "[dri] DRIScreenInit failed, disabling DRI.\n");
21602be438aSmrg
21702be438aSmrg    return FALSE;
21802be438aSmrg  }
21902be438aSmrg
22002be438aSmrg  /* Check the TDFX DRM version */
22102be438aSmrg  {
22202be438aSmrg     drmVersionPtr version = drmGetVersion(pTDFX->drmSubFD);
22302be438aSmrg     if (version) {
22402be438aSmrg        if (version->version_major != 1 ||
22502be438aSmrg            version->version_minor < 0) {
22602be438aSmrg           /* incompatible drm version */
22702be438aSmrg           xf86DrvMsg(pScreen->myNum, X_ERROR,
22802be438aSmrg                      "[dri] TDFXDRIScreenInit failed because of a version mismatch.\n"
22902be438aSmrg                      "[dri] tdfx.o kernel module version is %d.%d.%d but version 1.0.x is needed.\n"
23002be438aSmrg                      "[dri] Disabling the DRI.\n",
23102be438aSmrg                      version->version_major,
23202be438aSmrg                      version->version_minor,
23302be438aSmrg                      version->version_patchlevel);
23402be438aSmrg           TDFXDRICloseScreen(pScreen);
23502be438aSmrg           drmFreeVersion(version);
23602be438aSmrg           return FALSE;
23702be438aSmrg        }
23802be438aSmrg        drmFreeVersion(version);
23902be438aSmrg     }
24002be438aSmrg  }
24102be438aSmrg
24202be438aSmrg  pTDFXDRI->regsSize=TDFXIOMAPSIZE;
24302be438aSmrg  if (drmAddMap(pTDFX->drmSubFD, (drm_handle_t)pTDFX->MMIOAddr[0],
24402be438aSmrg		pTDFXDRI->regsSize, DRM_REGISTERS, 0, &pTDFXDRI->regs)<0) {
24502be438aSmrg    TDFXDRICloseScreen(pScreen);
24602be438aSmrg    xf86DrvMsg(pScreen->myNum, X_ERROR, "drmAddMap failed, disabling DRI.\n");
24702be438aSmrg    return FALSE;
24802be438aSmrg  }
24902be438aSmrg  xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] Registers = 0x%08x\n",
25002be438aSmrg	       pTDFXDRI->regs);
25102be438aSmrg
25202be438aSmrg  xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configs initialized\n" );
25302be438aSmrg
25402be438aSmrg  return TRUE;
25502be438aSmrg}
25602be438aSmrg
25702be438aSmrgvoid
25802be438aSmrgTDFXDRICloseScreen(ScreenPtr pScreen)
25902be438aSmrg{
2603a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
26102be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
26202be438aSmrg
26302be438aSmrg  DRICloseScreen(pScreen);
26402be438aSmrg
26502be438aSmrg  if (pTDFX->pDRIInfo) {
26602be438aSmrg    if (pTDFX->pDRIInfo->devPrivate) {
2673a56a767Smrg      free(pTDFX->pDRIInfo->devPrivate);
26802be438aSmrg      pTDFX->pDRIInfo->devPrivate=0;
26902be438aSmrg    }
27002be438aSmrg    DRIDestroyInfoRec(pTDFX->pDRIInfo);
27102be438aSmrg    pTDFX->pDRIInfo=0;
27202be438aSmrg  }
27302be438aSmrg}
27402be438aSmrg
27502be438aSmrgstatic Bool
27602be438aSmrgTDFXCreateContext(ScreenPtr pScreen, VisualPtr visual,
27702be438aSmrg		  drm_context_t hwContext, void *pVisualConfigPriv,
27802be438aSmrg		  DRIContextType contextStore)
27902be438aSmrg{
28002be438aSmrg  return TRUE;
28102be438aSmrg}
28202be438aSmrg
28302be438aSmrgstatic void
28402be438aSmrgTDFXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
28502be438aSmrg		   DRIContextType contextStore)
28602be438aSmrg{
28702be438aSmrg}
28802be438aSmrg
28902be438aSmrgBool
29002be438aSmrgTDFXDRIFinishScreenInit(ScreenPtr pScreen)
29102be438aSmrg{
2923a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
29302be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
29402be438aSmrg  TDFXDRIPtr pTDFXDRI;
29502be438aSmrg
29602be438aSmrg  pTDFX->pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
29702be438aSmrg
29802be438aSmrg  pTDFXDRI=(TDFXDRIPtr)pTDFX->pDRIInfo->devPrivate;
299880ed95aSmrg#ifdef XSERVER_LIBPCIACCESS
300880ed95aSmrg  pTDFXDRI->deviceID = DEVICE_ID(pTDFX->PciInfo[0]);
301880ed95aSmrg#else
302880ed95aSmrg  pTDFXDRI->deviceID = DEVICE_ID(pTDFX->PciInfo);
303880ed95aSmrg#endif
30402be438aSmrg  pTDFXDRI->width=pScrn->virtualX;
30502be438aSmrg  pTDFXDRI->height=pScrn->virtualY;
30602be438aSmrg  pTDFXDRI->mem=pScrn->videoRam*1024;
30702be438aSmrg  pTDFXDRI->cpp=pTDFX->cpp;
30802be438aSmrg  pTDFXDRI->stride=pTDFX->stride;
30902be438aSmrg  pTDFXDRI->fifoOffset=pTDFX->fifoOffset;
31002be438aSmrg  pTDFXDRI->fifoSize=pTDFX->fifoSize;
31102be438aSmrg  pTDFXDRI->textureOffset=pTDFX->texOffset;
31202be438aSmrg  pTDFXDRI->textureSize=pTDFX->texSize;
31302be438aSmrg  pTDFXDRI->fbOffset=pTDFX->fbOffset;
31402be438aSmrg  pTDFXDRI->backOffset=pTDFX->backOffset;
31502be438aSmrg  pTDFXDRI->depthOffset=pTDFX->depthOffset;
31602be438aSmrg  pTDFXDRI->sarea_priv_offset = sizeof(XF86DRISAREARec);
31702be438aSmrg  return DRIFinishScreenInit(pScreen);
31802be438aSmrg}
31902be438aSmrg
32002be438aSmrgstatic void
32102be438aSmrgTDFXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
32202be438aSmrg		   DRIContextType oldContextType, void *oldContext,
32302be438aSmrg		   DRIContextType newContextType, void *newContext)
32402be438aSmrg{
32502be438aSmrg}
32602be438aSmrg
32702be438aSmrgstatic void
32802be438aSmrgTDFXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
32902be438aSmrg{
3303a56a767Smrg#ifdef HAVE_XAA_H
33102be438aSmrg  ScreenPtr pScreen = pWin->drawable.pScreen;
3323a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
33302be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
33402be438aSmrg  BoxPtr pbox;
33502be438aSmrg  int nbox;
33602be438aSmrg
33702be438aSmrg  /* It looks nicer if these start out black */
33802be438aSmrg  pbox = REGION_RECTS(prgn);
33902be438aSmrg  nbox = REGION_NUM_RECTS(prgn);
34002be438aSmrg
34102be438aSmrg  TDFXSetupForSolidFill(pScrn, 0, GXcopy, -1);
34202be438aSmrg  while (nbox--) {
34302be438aSmrg    TDFXSelectBuffer(pTDFX, TDFX_BACK);
34402be438aSmrg    TDFXSubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
34502be438aSmrg				pbox->x2-pbox->x1, pbox->y2-pbox->y1);
34602be438aSmrg    TDFXSelectBuffer(pTDFX, TDFX_DEPTH);
34702be438aSmrg    TDFXSubsequentSolidFillRect(pScrn, pbox->x1, pbox->y1,
34802be438aSmrg				pbox->x2-pbox->x1, pbox->y2-pbox->y1);
34902be438aSmrg    pbox++;
35002be438aSmrg  }
35102be438aSmrg  TDFXSelectBuffer(pTDFX, TDFX_FRONT);
35202be438aSmrg
3533a56a767Smrg
35402be438aSmrg  pTDFX->AccelInfoRec->NeedToSync = TRUE;
3553a56a767Smrg#endif
35602be438aSmrg}
35702be438aSmrg
35802be438aSmrgstatic void
35902be438aSmrgTDFXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
36002be438aSmrg		   RegionPtr prgnSrc, CARD32 index)
36102be438aSmrg{
3623a56a767Smrg#ifdef HAVE_XAA_H
36302be438aSmrg  ScreenPtr pScreen = pParent->drawable.pScreen;
3643a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
36502be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
36602be438aSmrg  int dx, dy, xdir, ydir, i, x, y, nbox;
36702be438aSmrg  BoxPtr pbox;
36802be438aSmrg
36902be438aSmrg  dx = pParent->drawable.x - ptOldOrg.x;
37002be438aSmrg  dy = pParent->drawable.y - ptOldOrg.y;
37102be438aSmrg
37202be438aSmrg  DRIMoveBuffersHelper(pScreen, dx, dy, &xdir, &ydir, prgnSrc);
37302be438aSmrg
37402be438aSmrg  pbox = REGION_RECTS(prgnSrc);
37502be438aSmrg  nbox = REGION_NUM_RECTS(prgnSrc);
37602be438aSmrg
37702be438aSmrg  TDFXSetupForScreenToScreenCopy(pScrn, xdir, ydir, GXcopy, ~0, -1);
37802be438aSmrg
37902be438aSmrg  TDFXSelectBuffer(pTDFX, TDFX_BACK);
38002be438aSmrg  for(i = 0; i < nbox; i++) {
38102be438aSmrg     x = pbox[i].x1;
38202be438aSmrg     y = pbox[i].y1;
38302be438aSmrg     TDFXSubsequentScreenToScreenCopy(pScrn, x, y, x+dx, y+dy,
38402be438aSmrg                                      pbox[i].x2 - x, pbox[i].y2 - y);
38502be438aSmrg  }
38602be438aSmrg
38702be438aSmrg  TDFXSelectBuffer(pTDFX, TDFX_DEPTH);
38802be438aSmrg  for(i = 0; i < nbox; i++) {
38902be438aSmrg     x = pbox[i].x1;
39002be438aSmrg     y = pbox[i].y1;
39102be438aSmrg     TDFXSubsequentScreenToScreenCopy(pScrn, x, y, x+dx, y+dy,
39202be438aSmrg                                      pbox[i].x2 - x, pbox[i].y2 - y);
39302be438aSmrg  }
39402be438aSmrg
39502be438aSmrg  TDFXSelectBuffer(pTDFX, TDFX_FRONT);
39602be438aSmrg
39702be438aSmrg  pTDFX->AccelInfoRec->NeedToSync = TRUE;
3983a56a767Smrg#endif
3993a56a767Smrg
40002be438aSmrg}
40102be438aSmrg
40202be438aSmrg/*
40302be438aSmrg * the FullScreen DRI code is dead; this is just left in place to show how
40402be438aSmrg * to set up SLI mode.
40502be438aSmrg */
40602be438aSmrgstatic Bool
40702be438aSmrgTDFXDRIOpenFullScreen(ScreenPtr pScreen)
40802be438aSmrg{
40902be438aSmrg#if 0
41002be438aSmrg  ScrnInfoPtr pScrn;
41102be438aSmrg  TDFXPtr pTDFX;
41202be438aSmrg
41302be438aSmrg  xf86DrvMsg(pScreen->myNum, X_INFO, "OpenFullScreen\n");
4143a56a767Smrg  pScrn = xf86ScreenToScrn(pScreen);
41502be438aSmrg  pTDFX=TDFXPTR(pScrn);
41602be438aSmrg  if (pTDFX->numChips>1) {
41702be438aSmrg    TDFXSetupSLI(pScrn);
41802be438aSmrg  }
41902be438aSmrg#endif
42002be438aSmrg  return TRUE;
42102be438aSmrg}
42202be438aSmrg
42302be438aSmrgstatic Bool
42402be438aSmrgTDFXDRICloseFullScreen(ScreenPtr pScreen)
42502be438aSmrg{
42602be438aSmrg#if 0
42702be438aSmrg  ScrnInfoPtr pScrn;
42802be438aSmrg
42902be438aSmrg  xf86DrvMsg(pScreen->myNum, X_INFO, "CloseFullScreen\n");
4303a56a767Smrg  pScrn = xf86ScreenToScrn(pScreen);
43102be438aSmrg  TDFXDisableSLI(pScrn);
43202be438aSmrg#endif
43302be438aSmrg  return TRUE;
43402be438aSmrg}
43502be438aSmrg
43602be438aSmrgstatic void
43702be438aSmrgTDFXDRITransitionTo2d(ScreenPtr pScreen)
43802be438aSmrg{
4393a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
44002be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
44102be438aSmrg
44202be438aSmrg  xf86FreeOffscreenArea(pTDFX->reservedArea);
44302be438aSmrg}
44402be438aSmrg
44502be438aSmrgstatic void
44602be438aSmrgTDFXDRITransitionTo3d(ScreenPtr pScreen)
44702be438aSmrg{
4483a56a767Smrg  ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
44902be438aSmrg  TDFXPtr pTDFX = TDFXPTR(pScrn);
45002be438aSmrg  FBAreaPtr pArea;
45102be438aSmrg
45202be438aSmrg  if(pTDFX->overlayBuffer) {
45302be438aSmrg	xf86FreeOffscreenLinear(pTDFX->overlayBuffer);
45402be438aSmrg	pTDFX->overlayBuffer = NULL;
45502be438aSmrg  }
45602be438aSmrg
45702be438aSmrg  if(pTDFX->overlayBuffer2) {
45802be438aSmrg	xf86FreeOffscreenLinear(pTDFX->overlayBuffer2);
45902be438aSmrg	pTDFX->overlayBuffer2 = NULL;
46002be438aSmrg  }
46102be438aSmrg
46202be438aSmrg  if(pTDFX->textureBuffer) {
46302be438aSmrg	xf86FreeOffscreenArea(pTDFX->textureBuffer);
46402be438aSmrg	pTDFX->textureBuffer = NULL;
46502be438aSmrg  }
46602be438aSmrg
46702be438aSmrg  xf86PurgeUnlockedOffscreenAreas(pScreen);
46802be438aSmrg
46902be438aSmrg  pArea = xf86AllocateOffscreenArea(pScreen, pScrn->displayWidth,
47002be438aSmrg				    pTDFX->pixmapCacheLinesMin,
47102be438aSmrg				    pScrn->displayWidth, NULL, NULL, NULL);
47202be438aSmrg  pTDFX->reservedArea = xf86AllocateOffscreenArea(pScreen, pScrn->displayWidth,
47302be438aSmrg			pTDFX->pixmapCacheLinesMax - pTDFX->pixmapCacheLinesMin,
47402be438aSmrg			pScrn->displayWidth, NULL, NULL, NULL);
47502be438aSmrg  xf86FreeOffscreenArea(pArea);
47602be438aSmrg}
477