Guest User

Untitled

a guest
May 18th, 2013
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* $XFree86$ */
  2. /* $XdotOrg$ */
  3. /*
  4. * 2D Acceleration for SiS 315, 330 and 340 series
  5. *
  6. * Copyright (C) 2001-2005 by Thomas Winischhofer, Vienna, Austria
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1) Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2) Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3) The name of the author may not be used to endorse or promote products
  17. * derived from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  21. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. *
  31. * Author: Thomas Winischhofer <thomas@winischhofer.net>
  32. *
  33. * 2003/08/18: Rewritten for using VRAM command queue
  34. *
  35. */
  36.  
  37. #ifdef HAVE_CONFIG_H
  38. #include "config.h"
  39. #endif
  40.  
  41. #include "sis.h"
  42. #define SIS_NEED_MYMMIO
  43. #define SIS_NEED_ACCELBUF
  44. #include "sis_regs.h"
  45. #include "sis310_accel.h"
  46. /*
  47. #define ACCELDEBUG
  48. */
  49. #define FBOFFSET (pSiS->dhmOffset)
  50.  
  51. #define DEV_HEIGHT 0xfff /* "Device height of destination bitmap" */
  52.  
  53. #undef SIS_NEED_ARRAY
  54.  
  55. /* For XAA */
  56.  
  57. #ifdef SIS_USE_XAA
  58.  
  59. #define INCL_RENDER /* Use/Don't use RENDER extension acceleration */
  60.  
  61. #ifdef INCL_RENDER
  62. # ifdef RENDER
  63. # include "mipict.h"
  64. # include "dixstruct.h"
  65. # define SIS_NEED_ARRAY
  66. # undef SISNEWRENDER
  67. # ifdef XORG_VERSION_CURRENT
  68. //# if XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(6,7,0,0,0)
  69. # define SISNEWRENDER
  70. //# endif
  71. # endif
  72. # endif
  73. #endif
  74.  
  75. #endif /* XAA */
  76.  
  77. /* For EXA */
  78.  
  79. #ifdef SIS_USE_EXA
  80. #if 0
  81. #define SIS_HAVE_COMPOSITE /* Have our own EXA composite */
  82. #endif
  83. #ifdef SIS_HAVE_COMPOSITE
  84. #if 0
  85. #ifndef SIS_NEED_ARRAY
  86. #define SIS_NEED_ARRAY
  87. #endif
  88. #endif
  89. #endif
  90. #endif
  91.  
  92. #if defined(SIS_USE_XAA) && defined(INCL_RENDER) && defined(RENDER) /* XAA */
  93. static CARD32 SiSAlphaTextureFormats[2] = { PICT_a8 , 0 };
  94. static CARD32 SiSTextureFormats[2] = { PICT_a8r8g8b8, 0 };
  95. static CARD32 SiS3DAlphaTextureFormats[2] = { PICT_a8r8g8b8, 0 };
  96. #ifdef SISNEWRENDER
  97. static CARD32 SiSDstTextureFormats16[2] = { PICT_r5g6b5 , 0 };
  98. static CARD32 SiSDstTextureFormats32[3] = { PICT_x8r8g8b8, PICT_a8r8g8b8, 0 };
  99. #endif
  100. #endif
  101.  
  102. #ifdef SIS_USE_EXA /* EXA */
  103. void SiSScratchSave(ScreenPtr pScreen, ExaOffscreenArea *area);
  104. Bool SiSUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, int src_pitch);
  105. Bool SiSUploadToScratch(PixmapPtr pSrc, PixmapPtr pDst);
  106. Bool SiSDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, char *dst, int dst_pitch);
  107. #endif /* EXA */
  108.  
  109. void SISWriteBlitPacket(SISPtr pSiS, CARD32 *packet);
  110.  
  111. extern unsigned char SiSGetCopyROP(int rop);
  112. extern unsigned char SiSGetPatternROP(int rop);
  113.  
  114.  
  115. pthread_mutex_t *CmdQ_Lock;
  116.  
  117. void SiSOccpyCmdQue(SISPtr pSiS)
  118. {
  119. if(pSiS->DRIEnabled)
  120. pthread_mutex_lock(CmdQ_Lock);
  121.  
  122. return;
  123. }
  124.  
  125.  
  126. void SiSReleaseCmdQue(SISPtr pSiS)
  127. {
  128. if(pSiS->DRIEnabled)
  129. pthread_mutex_unlock(CmdQ_Lock);
  130. return;
  131. }
  132.  
  133. /* 3D-engine accel */
  134. extern Bool
  135. SiSSetupForCPUToScreenAlphaTexture3D (ScrnInfoPtr pScrn,
  136. int op, CARD16 red, CARD16 green,
  137. CARD16 blue, CARD16 alpha,
  138. #ifdef SISNEWRENDER
  139. CARD32 alphaType, CARD32 dstType,
  140. #else
  141. int alphaType,
  142. #endif
  143. CARD8 *alphaPtr,
  144. int alphaPitch, int width,
  145. int height, int flags);
  146.  
  147. extern void SiSSubsequentCPUToScreenTexture3D(ScrnInfoPtr pScrn,
  148. int dst_x, int dst_y,
  149. int src_x, int src_y,
  150. int width, int height);
  151.  
  152. volatile CARD32 dummybuf;
  153.  
  154. #ifdef SIS_NEED_ARRAY
  155. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  156. #define SiSRenderOpsMAX 0x2b
  157. #else
  158. #define SiSRenderOpsMAX 0x0f
  159. #endif
  160. static const CARD8 SiSRenderOps[] = { /* PictOpXXX 1 = supported, 0 = unsupported */
  161. 1, 1, 1, 1,
  162. 0, 0, 0, 0,
  163. 0, 0, 0, 0,
  164. 0, 0, 0, 0,
  165. 1, 1, 1, 0,
  166. 0, 0, 0, 0,
  167. 0, 0, 0, 0,
  168. 0, 0, 0, 0,
  169. 1, 1, 1, 0,
  170. 0, 0, 0, 0,
  171. 0, 0, 0, 0,
  172. 0, 0, 0, 0
  173. };
  174. #endif /* NEED ARRAY */
  175.  
  176. #ifdef SIS_NEED_ARRAY
  177. static void
  178. SiSCalcRenderAccelArray(ScrnInfoPtr pScrn)
  179. {
  180. SISPtr pSiS = SISPTR(pScrn);
  181. #ifdef SISDUALHEAD
  182. SISEntPtr pSiSEnt = pSiS->entityPrivate;;
  183. #endif
  184.  
  185. if(((pScrn->bitsPerPixel == 16) || (pScrn->bitsPerPixel == 32)) && pSiS->doRender) {
  186. int i, j;
  187. #ifdef SISDUALHEAD
  188. if(pSiSEnt) pSiS->RenderAccelArray = pSiSEnt->RenderAccelArray;
  189. #endif
  190. if(!pSiS->RenderAccelArray) {
  191. if((pSiS->RenderAccelArray = xnfcalloc(65536, 1))) {
  192. #ifdef SISDUALHEAD
  193. if(pSiSEnt) pSiSEnt->RenderAccelArray = pSiS->RenderAccelArray;
  194. #endif
  195. for(i = 0; i < 256; i++) {
  196. for(j = 0; j < 256; j++) {
  197. pSiS->RenderAccelArray[(i << 8) + j] = (i * j) / 255;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. #endif
  205.  
  206. #ifdef SIS_USE_EXA
  207. void
  208. SiSScratchSave(ScreenPtr pScreen, ExaOffscreenArea *area)
  209. {
  210. SISPtr pSiS = SISPTR(xf86ScreenToScrn(pScreen));
  211.  
  212. pSiS->exa_scratch = NULL;
  213. }
  214. #endif
  215.  
  216. static void
  217. SiSSync(ScrnInfoPtr pScrn)
  218. {
  219. SISPtr pSiS = SISPTR(pScrn);
  220.  
  221. #ifdef SIS_USE_XAA
  222. if(!pSiS->useEXA) {
  223. pSiS->DoColorExpand = FALSE;
  224. }
  225. #endif
  226.  
  227. pSiS->alphaBlitBusy = FALSE;
  228.  
  229. SiSIdle
  230. }
  231.  
  232. #ifdef SISVRAMQ
  233. static CARD32
  234. SISSiSUpdateQueue(SISPtr pSiS, CARD32 ttt, pointer tt)
  235. {
  236. SiSUpdateQueue
  237.  
  238. return ttt;
  239. }
  240. #endif
  241.  
  242. static void
  243. SiSSyncAccel(ScrnInfoPtr pScrn)
  244. {
  245. SISPtr pSiS = SISPTR(pScrn);
  246.  
  247. if(!pSiS->NoAccel) SiSSync(pScrn);
  248. }
  249.  
  250. static void
  251. SiSInitializeAccelerator(ScrnInfoPtr pScrn)
  252. {
  253. SISPtr pSiS = SISPTR(pScrn);
  254.  
  255. #ifdef SIS_USE_XAA
  256. pSiS->DoColorExpand = FALSE;
  257. #endif
  258. pSiS->alphaBlitBusy = FALSE;
  259.  
  260. if(!pSiS->NoAccel) {
  261.  
  262.  
  263.  
  264. #ifndef SISVRAMQ
  265. if(pSiS->ChipFlags & SiSCF_Integrated) {
  266. CmdQueLen = 0;
  267. } else {
  268. CmdQueLen = ((128 * 1024) / 4) - 64;
  269. }
  270. #endif
  271.  
  272. #ifdef SISVRAMQ
  273. if(pSiS->ChipFlags & SiSCF_DualPipe) {
  274. SiSSync(pScrn);
  275. SiSDualPipe(1); /* 1 = disable, 0 = enable */
  276. SiSSync(pScrn);
  277. }
  278. #endif
  279.  
  280. }
  281. }
  282.  
  283. static void
  284. SiSSetupForScreenToScreenCopy(ScrnInfoPtr pScrn,
  285. int xdir, int ydir, int rop,
  286. unsigned int planemask, int trans_color)
  287. {
  288. SISPtr pSiS = SISPTR(pScrn);
  289.  
  290. SiSOccpyCmdQue(pSiS);
  291. #ifdef ACCELDEBUG
  292. xf86DrvMsg(0, X_INFO, "XAA calling ScreenToScreenCopy\n");
  293. #endif
  294.  
  295. #ifdef SISVRAMQ
  296. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  297. SiSCheckQueue(16 * 2);
  298. SiSSetupSRCPitchDSTRect(pSiS->scrnOffset, pSiS->scrnOffset, DEV_HEIGHT)
  299. #else
  300. SiSSetupDSTColorDepth(pSiS->DstColor);
  301. SiSSetupSRCPitch(pSiS->scrnOffset)
  302. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  303. #endif
  304.  
  305. if(trans_color != -1) {
  306. SiSSetupROP(0x0A)
  307. SiSSetupSRCTrans(trans_color)
  308. SiSSetupCMDFlag(TRANSPARENT_BITBLT)
  309. } else {
  310. SiSSetupROP(SiSGetCopyROP(rop))
  311. /* Set command - not needed, both 0 */
  312. /* SiSSetupCMDFlag(BITBLT | SRCVIDEO) */
  313. }
  314.  
  315. #ifndef SISVRAMQ
  316. SiSSetupCMDFlag(pSiS->SiS310_AccelDepth)
  317. #endif
  318.  
  319. #ifdef SISVRAMQ
  320. SiSSyncWP
  321. #endif
  322. SiSReleaseCmdQue(pSiS);
  323.  
  324. /* The chip is smart enough to know the direction */
  325. }
  326.  
  327. static void
  328. SiSSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn,
  329. int src_x, int src_y, int dst_x, int dst_y,
  330. int width, int height)
  331. {
  332. SISPtr pSiS = SISPTR(pScrn);
  333. CARD32 srcbase, dstbase;
  334. int mymin, mymax;
  335.  
  336. #ifdef ACCELDEBUG
  337. xf86DrvMsg(0, X_INFO, "XAA calling SubsequentScreenToScreenCopy\n");
  338. #endif
  339.  
  340. srcbase = dstbase = 0;
  341. mymin = min(src_y, dst_y);
  342. mymax = max(src_y, dst_y);
  343.  
  344. /* Libxaa.a has a bug: The tilecache cannot operate
  345. * correctly if there are 512x512 slots, but no 256x256
  346. * slots. This leads to catastrophic data fed to us.
  347. * Filter this out here and warn the user.
  348. * Fixed in 4.3.99.10 (?) and Debian's 4.3.0.1
  349. */
  350. #if (XF86_VERSION_CURRENT < XF86_VERSION_NUMERIC(4,3,99,10,0)) && (XF86_VERSION_CURRENT != XF86_VERSION_NUMERIC(4,3,0,1,0))
  351. if((src_x < 0) ||
  352. (dst_x < 0) ||
  353. (src_y < 0) ||
  354. (dst_y < 0) ||
  355. (width <= 0) ||
  356. (height <= 0)) {
  357. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  358. "BitBlit fatal error: Illegal coordinates:\n");
  359. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  360. "Source x %d y %d, dest x %d y %d, width %d height %d\n",
  361. src_x, src_y, dst_x, dst_y, width, height);
  362. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  363. "This is very probably caused by a known bug in libxaa.a.\n");
  364. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  365. "Please update libxaa.a to avoid this error.\n");
  366. return;
  367. }
  368. #endif
  369.  
  370. /* Although the chip knows the direction to use
  371. * if the source and destination areas overlap,
  372. * that logic fails if we fiddle with the bitmap
  373. * addresses. Therefore, we check if the source
  374. * and destination blitting areas overlap and
  375. * adapt the bitmap addresses synchronously
  376. * if the coordinates exceed the valid range.
  377. * The the areas do not overlap, we do our
  378. * normal check.
  379. */
  380. if((mymax - mymin) < height) {
  381. if((src_y >= 2048) || (dst_y >= 2048)) {
  382. srcbase = pSiS->scrnOffset * mymin;
  383. dstbase = pSiS->scrnOffset * mymin;
  384. src_y -= mymin;
  385. dst_y -= mymin;
  386. }
  387. } else {
  388. if(src_y >= 2048) {
  389. srcbase = pSiS->scrnOffset * src_y;
  390. src_y = 0;
  391. }
  392. if((dst_y >= pScrn->virtualY) || (dst_y >= 2048)) {
  393. dstbase = pSiS->scrnOffset * dst_y;
  394. dst_y = 0;
  395. }
  396. }
  397.  
  398. srcbase += FBOFFSET;
  399. dstbase += FBOFFSET;
  400.  
  401. SiSOccpyCmdQue(pSiS);
  402. #ifdef SISVRAMQ
  403. SiSCheckQueue(16 * 3);
  404. SiSSetupSRCDSTBase(srcbase, dstbase)
  405. SiSSetupSRCDSTXY(src_x, src_y, dst_x, dst_y)
  406. SiSSetRectDoCMD(width,height)
  407. #else
  408. SiSSetupSRCBase(srcbase);
  409. SiSSetupDSTBase(dstbase);
  410. SiSSetupRect(width, height)
  411. SiSSetupSRCXY(src_x, src_y)
  412. SiSSetupDSTXY(dst_x, dst_y)
  413. SiSDoCMD
  414. #endif
  415. SiSReleaseCmdQue(pSiS);
  416.  
  417. }
  418.  
  419. static void
  420. SiSSetupForSolidFill(ScrnInfoPtr pScrn, int color,
  421. int rop, unsigned int planemask)
  422. {
  423. SISPtr pSiS = SISPTR(pScrn);
  424.  
  425. if(pSiS->disablecolorkeycurrent || pSiS->nocolorkey) {
  426. if((CARD32)color == pSiS->colorKey) {
  427. rop = 5; /* NOOP */
  428. }
  429. }
  430.  
  431. #ifdef ACCELDEBUG
  432. xf86DrvMsg(0, X_INFO, "XAA calling SolidFill\n");
  433. #endif
  434.  
  435. SiSOccpyCmdQue(pSiS);
  436. #ifdef SISVRAMQ
  437. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  438. SiSCheckQueue(16 * 1);
  439. SiSSetupPATFGDSTRect(color, pSiS->scrnOffset, DEV_HEIGHT)
  440. SiSSetupROP(SiSGetPatternROP(rop))
  441. SiSSetupCMDFlag(PATFG)
  442. SiSSyncWP
  443. #else
  444. SiSSetupPATFG(color)
  445. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  446. SiSSetupDSTColorDepth(pSiS->DstColor);
  447. SiSSetupROP(SiSGetPatternROP(rop))
  448. SiSSetupCMDFlag(PATFG | pSiS->SiS310_AccelDepth)
  449. #endif
  450. SiSReleaseCmdQue(pSiS);
  451. }
  452.  
  453. static void
  454. SiSSubsequentSolidFillRect(ScrnInfoPtr pScrn,
  455. int x, int y, int w, int h)
  456. {
  457. SISPtr pSiS = SISPTR(pScrn);
  458. CARD32 dstbase = 0;
  459.  
  460. #ifdef ACCELDEBUG
  461. xf86DrvMsg(0, X_INFO, "XAA calling SubsequentSolidFillRect\n");
  462. #endif
  463.  
  464. if(y >= 2048) {
  465. dstbase = pSiS->scrnOffset * y;
  466. y = 0;
  467. }
  468.  
  469. dstbase += FBOFFSET;
  470.  
  471. pSiS->CommandReg &= ~(T_XISMAJORL | T_XISMAJORR |
  472. T_L_X_INC | T_L_Y_INC |
  473. T_R_X_INC | T_R_Y_INC |
  474. TRAPAZOID_FILL);
  475.  
  476. /* SiSSetupCMDFlag(BITBLT) - BITBLT = 0 */
  477.  
  478. SiSOccpyCmdQue(pSiS);
  479. #ifdef SISVRAMQ
  480. SiSCheckQueue(16 * 2)
  481. SiSSetupDSTXYRect(x, y, w, h)
  482. SiSSetupDSTBaseDoCMD(dstbase)
  483. #else
  484. SiSSetupDSTBase(dstbase)
  485. SiSSetupDSTXY(x, y)
  486. SiSSetupRect(w, h)
  487. SiSDoCMD
  488. #endif
  489. SiSReleaseCmdQue(pSiS);
  490. }
  491.  
  492. #ifdef SIS_USE_XAA /* ---------------------------- XAA -------------------------- */
  493.  
  494. static void
  495. SiSSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop,
  496. unsigned int planemask)
  497. {
  498. SISPtr pSiS = SISPTR(pScrn);
  499.  
  500. #ifdef ACCELDEBUG
  501. xf86DrvMsg(0, X_INFO, "XAA calling SolidLine\n");
  502. #endif
  503.  
  504. SiSOccpyCmdQue(pSiS);
  505. #ifdef SISVRAMQ
  506. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  507. SiSCheckQueue(16 * 3);
  508. SiSSetupLineCountPeriod(1, 1)
  509. SiSSetupPATFGDSTRect(color, pSiS->scrnOffset, DEV_HEIGHT)
  510. SiSSetupROP(SiSGetPatternROP(rop))
  511. SiSSetupCMDFlag(PATFG | LINE)
  512. SiSSyncWP
  513. #else
  514. SiSSetupLineCount(1)
  515. SiSSetupPATFG(color)
  516. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  517. SiSSetupDSTColorDepth(pSiS->DstColor)
  518. SiSSetupROP(SiSGetPatternROP(rop))
  519. SiSSetupCMDFlag(PATFG | LINE | pSiS->SiS310_AccelDepth)
  520. #endif
  521. SiSReleaseCmdQue(pSiS);
  522. }
  523.  
  524. static void
  525. SiSSubsequentSolidTwoPointLine(ScrnInfoPtr pScrn,
  526. int x1, int y1, int x2, int y2, int flags)
  527. {
  528. SISPtr pSiS = SISPTR(pScrn);
  529. int miny, maxy;
  530. CARD32 dstbase = 0;
  531.  
  532. #ifdef ACCELDEBUG
  533. xf86DrvMsg(0, X_INFO, "XAA calling SubsequentSolidTwoPointLine\n");
  534. #endif
  535.  
  536. miny = (y1 > y2) ? y2 : y1;
  537. maxy = (y1 > y2) ? y1 : y2;
  538. if(maxy >= 2048) {
  539. dstbase = pSiS->scrnOffset*miny;
  540. y1 -= miny;
  541. y2 -= miny;
  542. }
  543.  
  544. dstbase += FBOFFSET;
  545.  
  546. if(flags & OMIT_LAST) {
  547. SiSSetupCMDFlag(NO_LAST_PIXEL)
  548. } else {
  549. pSiS->CommandReg &= ~(NO_LAST_PIXEL);
  550. }
  551.  
  552. SiSOccpyCmdQue(pSiS);
  553. #ifdef SISVRAMQ
  554. SiSCheckQueue(16 * 2);
  555. SiSSetupX0Y0X1Y1(x1, y1, x2, y2)
  556. SiSSetupDSTBaseDoCMD(dstbase)
  557. #else
  558. SiSSetupDSTBase(dstbase)
  559. SiSSetupX0Y0(x1, y1)
  560. SiSSetupX1Y1(x2, y2)
  561. SiSDoCMD
  562. #endif
  563. SiSReleaseCmdQue(pSiS);
  564. }
  565.  
  566. static void
  567. SiSSubsequentSolidHorzVertLine(ScrnInfoPtr pScrn,
  568. int x, int y, int len, int dir)
  569. {
  570. SISPtr pSiS = SISPTR(pScrn);
  571. CARD32 dstbase = 0;
  572.  
  573. #ifdef ACCELDEBUG
  574. xf86DrvMsg(0, X_INFO, " XAA calling SubsequentSolidTwoPointLine\n");
  575. #endif
  576.  
  577. len--; /* starting point is included! */
  578.  
  579. if((y >= 2048) || ((y + len) >= 2048)) {
  580. dstbase = pSiS->scrnOffset * y;
  581. y = 0;
  582. }
  583.  
  584. dstbase += FBOFFSET;
  585.  
  586. SiSOccpyCmdQue(pSiS);
  587. #ifdef SISVRAMQ
  588. SiSCheckQueue(16 * 2);
  589. if(dir == DEGREES_0) {
  590. SiSSetupX0Y0X1Y1(x, y, (x + len), y)
  591. } else {
  592. SiSSetupX0Y0X1Y1(x, y, x, (y + len))
  593. }
  594. SiSSetupDSTBaseDoCMD(dstbase)
  595. #else
  596. SiSSetupDSTBase(dstbase)
  597. SiSSetupX0Y0(x,y)
  598. if(dir == DEGREES_0) {
  599. SiSSetupX1Y1(x + len, y);
  600. } else {
  601. SiSSetupX1Y1(x, y + len);
  602. }
  603. SiSDoCMD
  604. #endif
  605. SiSReleaseCmdQue(pSiS);
  606. }
  607.  
  608. static void
  609. SiSSetupForDashedLine(ScrnInfoPtr pScrn,
  610. int fg, int bg, int rop, unsigned int planemask,
  611. int length, unsigned char *pattern)
  612. {
  613. SISPtr pSiS = SISPTR(pScrn);
  614.  
  615. #ifdef ACCELDEBUG
  616. xf86DrvMsg(0, X_INFO, " XAA calling SetupForDashedLine\n");
  617. #endif
  618.  
  619. SiSOccpyCmdQue(pSiS);
  620. #ifdef SISVRAMQ
  621. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  622. SiSCheckQueue(16 * 3);
  623. SiSSetupLineCountPeriod(1, (length - 1))
  624. SiSSetupStyle(*pattern,*(pattern + 4))
  625. SiSSetupPATFGDSTRect(fg, pSiS->scrnOffset, DEV_HEIGHT)
  626. #else
  627. SiSSetupLineCount(1)
  628. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  629. SiSSetupDSTColorDepth(pSiS->DstColor);
  630. SiSSetupStyleLow(*pattern)
  631. SiSSetupStyleHigh(*(pattern + 4))
  632. SiSSetupStylePeriod(length - 1);
  633. SiSSetupPATFG(fg)
  634. #endif
  635.  
  636. SiSSetupROP(SiSGetPatternROP(rop))
  637.  
  638. SiSSetupCMDFlag(LINE | LINE_STYLE)
  639.  
  640. if(bg != -1) {
  641. SiSSetupPATBG(bg)
  642. } else {
  643. SiSSetupCMDFlag(TRANSPARENT)
  644. }
  645. #ifndef SISVRAMQ
  646. SiSSetupCMDFlag(pSiS->SiS310_AccelDepth)
  647. #endif
  648.  
  649. #ifdef SISVRAMQ
  650. SiSSyncWP
  651. #endif
  652. SiSReleaseCmdQue(pSiS);
  653. }
  654.  
  655. static void
  656. SiSSubsequentDashedTwoPointLine(ScrnInfoPtr pScrn,
  657. int x1, int y1, int x2, int y2,
  658. int flags, int phase)
  659. {
  660. SISPtr pSiS = SISPTR(pScrn);
  661. CARD32 dstbase, miny, maxy;
  662.  
  663. #ifdef ACCELDEBUG
  664. xf86DrvMsg(0, X_INFO, " XAA calling SubsequentDashedTwoPointLine\n");
  665. #endif
  666.  
  667. dstbase = 0;
  668. miny = (y1 > y2) ? y2 : y1;
  669. maxy = (y1 > y2) ? y1 : y2;
  670. if(maxy >= 2048) {
  671. dstbase = pSiS->scrnOffset * miny;
  672. y1 -= miny;
  673. y2 -= miny;
  674. }
  675.  
  676. dstbase += FBOFFSET;
  677.  
  678. if(flags & OMIT_LAST) {
  679. SiSSetupCMDFlag(NO_LAST_PIXEL)
  680. } else {
  681. pSiS->CommandReg &= ~(NO_LAST_PIXEL);
  682. }
  683.  
  684. SiSOccpyCmdQue(pSiS);
  685. #ifdef SISVRAMQ
  686. SiSCheckQueue(16 * 2);
  687. SiSSetupX0Y0X1Y1(x1, y1, x2, y2)
  688. SiSSetupDSTBaseDoCMD(dstbase)
  689. #else
  690. SiSSetupDSTBase(dstbase)
  691. SiSSetupX0Y0(x1, y1)
  692. SiSSetupX1Y1(x2, y2)
  693. SiSDoCMD
  694. #endif
  695. SiSReleaseCmdQue(pSiS);
  696. }
  697.  
  698. static void
  699. SiSSetupForMonoPatternFill(ScrnInfoPtr pScrn,
  700. int patx, int paty, int fg, int bg,
  701. int rop, unsigned int planemask)
  702. {
  703. SISPtr pSiS = SISPTR(pScrn);
  704.  
  705. #ifdef ACCELDEBUG
  706. xf86DrvMsg(0, X_INFO, " XAA calling SetupForMonoPatternFill\n");
  707. #endif
  708.  
  709. SiSOccpyCmdQue(pSiS);
  710. #ifdef SISVRAMQ
  711. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  712. SiSCheckQueue(16 * 3);
  713. SiSSetupPATFGDSTRect(fg, pSiS->scrnOffset, DEV_HEIGHT)
  714. #else
  715. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  716. SiSSetupDSTColorDepth(pSiS->DstColor);
  717. #endif
  718.  
  719. SiSSetupMONOPAT(patx,paty)
  720.  
  721. SiSSetupROP(SiSGetPatternROP(rop))
  722.  
  723. #ifdef SISVRAMQ
  724. SiSSetupCMDFlag(PATMONO)
  725. #else
  726. SiSSetupPATFG(fg)
  727. SiSSetupCMDFlag(PATMONO | pSiS->SiS310_AccelDepth)
  728. #endif
  729.  
  730. if(bg != -1) {
  731. SiSSetupPATBG(bg)
  732. } else {
  733. SiSSetupCMDFlag(TRANSPARENT)
  734. }
  735.  
  736. #ifdef SISVRAMQ
  737. SiSSyncWP
  738. #endif
  739. SiSReleaseCmdQue(pSiS);
  740.  
  741. }
  742.  
  743. static void
  744. SiSSubsequentMonoPatternFill(ScrnInfoPtr pScrn,
  745. int patx, int paty,
  746. int x, int y, int w, int h)
  747. {
  748. SISPtr pSiS = SISPTR(pScrn);
  749. CARD32 dstbase = 0;
  750.  
  751. #ifdef ACCELDEBUG
  752. xf86DrvMsg(0, X_INFO, " XAA calling SubsequentMonoPatternFill\n");
  753.  
  754. #endif
  755.  
  756. if(y >= 2048) {
  757. dstbase = pSiS->scrnOffset * y;
  758. y = 0;
  759. }
  760.  
  761. dstbase += FBOFFSET;
  762.  
  763. /* Clear commandReg because Setup can be used for Rect and Trap */
  764. pSiS->CommandReg &= ~(T_XISMAJORL | T_XISMAJORR |
  765. T_L_X_INC | T_L_Y_INC |
  766. T_R_X_INC | T_R_Y_INC |
  767. TRAPAZOID_FILL);
  768.  
  769. SiSOccpyCmdQue(pSiS);
  770. #ifdef SISVRAMQ
  771. SiSCheckQueue(16 * 2);
  772. SiSSetupDSTXYRect(x,y,w,h)
  773. SiSSetupDSTBaseDoCMD(dstbase)
  774. #else
  775. SiSSetupDSTBase(dstbase)
  776. SiSSetupDSTXY(x,y)
  777. SiSSetupRect(w,h)
  778. SiSDoCMD
  779. #endif
  780. SiSReleaseCmdQue(pSiS);
  781.  
  782. }
  783.  
  784. #ifdef SISVRAMQ
  785. static void
  786. SiSSetupForColor8x8PatternFill(ScrnInfoPtr pScrn, int patternx, int patterny,
  787. int rop, unsigned int planemask, int trans_col)
  788. {
  789. SISPtr pSiS = SISPTR(pScrn);
  790. int j = pSiS->CurrentLayout.bytesPerPixel;
  791. CARD32 *patadr = (CARD32 *)(pSiS->FbBase + (patterny * pSiS->scrnOffset) +
  792. (patternx * j));
  793.  
  794.  
  795. #ifdef ACCELDEBUG
  796. xf86DrvMsg(0, X_INFO, " XAA calling ForColor8x8PatternFill\n");
  797. #endif
  798.  
  799. SiSOccpyCmdQue(pSiS);
  800. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  801. SiSCheckQueue(16 * 3);
  802.  
  803. SiSSetupDSTRectBurstHeader(pSiS->scrnOffset, DEV_HEIGHT,
  804. PATTERN_REG, (pSiS->CurrentLayout.bitsPerPixel << 1))
  805.  
  806. while(j--) {
  807. SiSSetupPatternRegBurst(patadr[0], patadr[1], patadr[2], patadr[3]);
  808. SiSSetupPatternRegBurst(patadr[4], patadr[5], patadr[6], patadr[7]);
  809. SiSSetupPatternRegBurst(patadr[8], patadr[9], patadr[10], patadr[11]);
  810. SiSSetupPatternRegBurst(patadr[12], patadr[13], patadr[14], patadr[15]);
  811. patadr += 16; /* = 64 due to (CARD32 *) */
  812. }
  813.  
  814. SiSSetupROP(SiSGetPatternROP(rop))
  815.  
  816. SiSSetupCMDFlag(PATPATREG)
  817.  
  818. SiSSyncWP
  819.  
  820. SiSReleaseCmdQue(pSiS);
  821. }
  822.  
  823. static void
  824. SiSSubsequentColor8x8PatternFillRect(ScrnInfoPtr pScrn, int patternx,
  825. int patterny, int x, int y, int w, int h)
  826. {
  827. SISPtr pSiS = SISPTR(pScrn);
  828. CARD32 dstbase = 0;
  829.  
  830. #ifdef ACCELDEBUG
  831. xf86DrvMsg(0, X_INFO, " XAA calling SubsequentColor8x8PatternFillRect\n");
  832. #endif
  833.  
  834.  
  835.  
  836. if(y >= 2048) {
  837. dstbase = pSiS->scrnOffset * y;
  838. y = 0;
  839. }
  840.  
  841. dstbase += FBOFFSET;
  842.  
  843. /* SiSSetupCMDFlag(BITBLT) - BITBLT = 0 */
  844.  
  845. SiSOccpyCmdQue(pSiS);
  846.  
  847. SiSCheckQueue(16 * 2)
  848. SiSSetupDSTXYRect(x, y, w, h)
  849. SiSSetupDSTBaseDoCMD(dstbase)
  850.  
  851. SiSReleaseCmdQue(pSiS);
  852. }
  853. #endif
  854.  
  855. #ifdef SISDUALHEAD
  856. static void
  857. SiSRestoreAccelState(ScrnInfoPtr pScrn)
  858. {
  859. SISPtr pSiS = SISPTR(pScrn);
  860.  
  861. pSiS->ColorExpandBusy = FALSE;
  862. pSiS->alphaBlitBusy = FALSE;
  863. SiSIdle
  864. }
  865. #endif
  866.  
  867. /* ---- RENDER ---- */
  868.  
  869. #if defined(RENDER) && defined(INCL_RENDER)
  870. static void
  871. SiSRenderCallback(ScrnInfoPtr pScrn)
  872. {
  873. SISPtr pSiS = SISPTR(pScrn);
  874.  
  875. #ifdef ACCELDEBUG
  876. xf86DrvMsg(0, X_INFO, " XAA calling SiSRenderCallback\n");
  877. #endif
  878.  
  879. if((currentTime.milliseconds > pSiS->RenderTime) && pSiS->AccelLinearScratch) {
  880. xf86FreeOffscreenLinear(pSiS->AccelLinearScratch);
  881. pSiS->AccelLinearScratch = NULL;
  882. }
  883.  
  884. if(!pSiS->AccelLinearScratch) {
  885. pSiS->RenderCallback = NULL;
  886. }
  887. }
  888.  
  889. #define RENDER_DELAY 15000
  890.  
  891.  
  892. /* for extern referred, we remove the type "static"*/
  893. Bool
  894. SiSAllocateLinear(ScrnInfoPtr pScrn, int sizeNeeded)
  895. {
  896. SISPtr pSiS = SISPTR(pScrn);
  897.  
  898. pSiS->RenderTime = currentTime.milliseconds + RENDER_DELAY;
  899. pSiS->RenderCallback = SiSRenderCallback;
  900.  
  901. #ifdef ACCELDEBUG
  902. xf86DrvMsg(0, X_INFO, " XAA calling SiSAllocateLinear\n");
  903. #endif
  904.  
  905. if(pSiS->AccelLinearScratch) {
  906. if(pSiS->AccelLinearScratch->size >= sizeNeeded) {
  907. return TRUE;
  908. } else {
  909. if(pSiS->alphaBlitBusy) {
  910. pSiS->alphaBlitBusy = FALSE;
  911. SiSIdle
  912. }
  913. if(xf86ResizeOffscreenLinear(pSiS->AccelLinearScratch, sizeNeeded)) {
  914. return TRUE;
  915. }
  916. xf86FreeOffscreenLinear(pSiS->AccelLinearScratch);
  917. pSiS->AccelLinearScratch = NULL;
  918. }
  919. }
  920.  
  921. pSiS->AccelLinearScratch = xf86AllocateOffscreenLinear(
  922. pScrn->pScreen, sizeNeeded, 32,
  923. NULL, NULL, NULL);
  924.  
  925. return(pSiS->AccelLinearScratch != NULL);
  926. }
  927.  
  928. static Bool
  929. SiSSetupForCPUToScreenAlphaTexture(ScrnInfoPtr pScrn,
  930. int op, CARD16 red, CARD16 green,
  931. CARD16 blue, CARD16 alpha,
  932. #ifdef SISNEWRENDER
  933. CARD32 alphaType, CARD32 dstType,
  934. #else
  935. int alphaType,
  936. #endif
  937. CARD8 *alphaPtr,
  938. int alphaPitch, int width,
  939. int height, int flags)
  940. {
  941. SISPtr pSiS = SISPTR(pScrn);
  942. unsigned char *renderaccelarray;
  943. CARD32 *dstPtr;
  944. int x, pitch, sizeNeeded;
  945. int sbpp = pSiS->CurrentLayout.bytesPerPixel;
  946. int sbppshift = sbpp >> 1; /* 8->0, 16->1, 32->2 */
  947. CARD8 myalpha;
  948. Bool docopy = TRUE;
  949.  
  950. #ifdef ACCELDEBUG
  951. xf86DrvMsg(0, X_INFO, "AT(1): op %d t %x ARGB %x %x %x %x, w %d h %d pch %d\n",
  952. op, alphaType, /*dstType, */alpha, red, green, blue, width, height, alphaPitch);
  953. #endif
  954.  
  955. if((width > 2048) || (height > 2048)) return FALSE;
  956.  
  957. #ifdef SISVRAMQ
  958. if(op > SiSRenderOpsMAX) return FALSE;
  959. if(!SiSRenderOps[op]) return FALSE;
  960. #else
  961. if(op != PictOpOver) return FALSE;
  962. #endif
  963.  
  964. if(!((renderaccelarray = pSiS->RenderAccelArray)))
  965. return FALSE;
  966.  
  967. #ifdef ACCELDEBUG
  968. xf86DrvMsg(0, X_INFO, "AT(2): op %d t %x ARGB %x %x %x %x, w %d h %d pch %d\n",
  969. op, alphaType, alpha, red, green, blue, width, height, alphaPitch);
  970. #endif
  971.  
  972. pitch = (width + 31) & ~31;
  973. sizeNeeded = (pitch << 2) * height; /* Source a8 (=8bit), expand to A8R8G8B8 (=32bit) */
  974.  
  975. if(!SiSAllocateLinear(pScrn, (sizeNeeded + sbpp - 1) >> sbppshift))
  976. return FALSE;
  977.  
  978. red &= 0xff00;
  979. green &= 0xff00;
  980. blue &= 0xff00;
  981.  
  982. SiSOccpyCmdQue(pSiS);
  983.  
  984. #ifdef SISVRAMQ
  985. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  986. switch(op) {
  987. case PictOpClear:
  988. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  989. case PictOpDisjointClear:
  990. case PictOpConjointClear:
  991. #endif
  992. SiSSetupPATFGDSTRect(0, pSiS->scrnOffset, DEV_HEIGHT)
  993. /* SiSSetupROP(0x00) - is already 0 */
  994. SiSSetupCMDFlag(PATFG)
  995. docopy = FALSE;
  996. break;
  997. case PictOpSrc:
  998. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  999. case PictOpDisjointSrc:
  1000. case PictOpConjointSrc:
  1001. #endif
  1002. SiSSetupSRCPitchDSTRect((pitch << 2), pSiS->scrnOffset, DEV_HEIGHT);
  1003. SiSSetupAlpha(0xff)
  1004. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_NODESTALPHA)
  1005. break;
  1006. case PictOpDst:
  1007. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  1008. case PictOpDisjointDst:
  1009. case PictOpConjointDst:
  1010. #endif
  1011. SiSSetupSRCPitchDSTRect((pitch << 2), pSiS->scrnOffset, DEV_HEIGHT);
  1012. SiSSetupAlpha(0x00)
  1013. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_CONSTANTALPHA)
  1014. docopy = FALSE;
  1015. break;
  1016. case PictOpOver:
  1017. SiSSetupSRCPitchDSTRect((pitch << 2), pSiS->scrnOffset, DEV_HEIGHT);
  1018. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_PERPIXELALPHA)
  1019. break;
  1020. }
  1021. SiSSyncWP
  1022. #else
  1023. SiSSetupDSTColorDepth(pSiS->DstColor);
  1024. SiSSetupSRCPitch((pitch << 2));
  1025. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  1026. SiSSetupROP(0)
  1027. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_PERPIXELALPHA | pSiS->SiS310_AccelDepth)
  1028. #endif
  1029. SiSReleaseCmdQue(pSiS);
  1030.  
  1031. /* Don't need source for clear and dest */
  1032. if(!docopy) return TRUE;
  1033.  
  1034. dstPtr = (CARD32*)(pSiS->FbBase + (pSiS->AccelLinearScratch->offset << sbppshift));
  1035.  
  1036. if(pSiS->alphaBlitBusy) {
  1037. pSiS->alphaBlitBusy = FALSE;
  1038. SiSIdle
  1039. }
  1040.  
  1041. if(alpha == 0xffff) {
  1042.  
  1043. while(height--) {
  1044. for(x = 0; x < width; x++) {
  1045. myalpha = alphaPtr[x];
  1046. dstPtr[x] = (renderaccelarray[red + myalpha] << 16) |
  1047. (renderaccelarray[green + myalpha] << 8) |
  1048. renderaccelarray[blue + myalpha] |
  1049. myalpha << 24;
  1050. }
  1051. dstPtr += pitch;
  1052. alphaPtr += alphaPitch;
  1053. }
  1054.  
  1055. } else {
  1056.  
  1057. alpha &= 0xff00;
  1058.  
  1059. while(height--) {
  1060. for(x = 0; x < width; x++) {
  1061. myalpha = alphaPtr[x];
  1062. dstPtr[x] = (renderaccelarray[alpha + myalpha] << 24) |
  1063. (renderaccelarray[red + myalpha] << 16) |
  1064. (renderaccelarray[green + myalpha] << 8) |
  1065. renderaccelarray[blue + myalpha];
  1066. }
  1067. dstPtr += pitch;
  1068. alphaPtr += alphaPitch;
  1069. }
  1070.  
  1071. }
  1072.  
  1073. return TRUE;
  1074. }
  1075.  
  1076. static Bool
  1077. SiSSetupForCPUToScreenTexture(ScrnInfoPtr pScrn,
  1078. int op,
  1079. #ifdef SISNEWRENDER
  1080. CARD32 texType, CARD32 dstType,
  1081. #else
  1082. int texType,
  1083. #endif
  1084. CARD8 *texPtr,
  1085. int texPitch, int width,
  1086. int height, int flags)
  1087. {
  1088. SISPtr pSiS = SISPTR(pScrn);
  1089. CARD8 *dst;
  1090. int pitch, sizeNeeded;
  1091. int sbpp = pSiS->CurrentLayout.bytesPerPixel;
  1092. int sbppshift = sbpp >> 1; /* 8->0, 16->1, 32->2 */
  1093. int bppshift = PICT_FORMAT_BPP(texType) >> 4; /* 8->0, 16->1, 32->2 */
  1094. Bool docopy = TRUE;
  1095.  
  1096. #ifdef ACCELDEBUG
  1097. xf86DrvMsg(0, X_INFO, "T: type %x op %d w %d h %d T-pitch %d\n",
  1098. texType, op, width, height, texPitch);
  1099. #endif
  1100.  
  1101. SiSOccpyCmdQue(pSiS);
  1102. #ifdef SISVRAMQ
  1103. if(op > SiSRenderOpsMAX) return FALSE;
  1104. if(!SiSRenderOps[op]) return FALSE;
  1105. #else
  1106. if(op != PictOpOver) return FALSE;
  1107. #endif
  1108.  
  1109. if((width > 2048) || (height > 2048)) return FALSE;
  1110.  
  1111. pitch = (width + 31) & ~31;
  1112. sizeNeeded = (pitch << bppshift) * height;
  1113.  
  1114. #ifdef ACCELDEBUG
  1115. xf86DrvMsg(0, X_INFO, "T: %x op %x w %d h %d T-pitch %d size %d (%d %d %d)\n",
  1116. texType, op, width, height, texPitch, sizeNeeded, sbpp, sbppshift, bppshift);
  1117. #endif
  1118.  
  1119. if(!SiSAllocateLinear(pScrn, (sizeNeeded + sbpp - 1) >> sbppshift))
  1120. return FALSE;
  1121.  
  1122. width <<= bppshift; /* -> bytes (for engine and memcpy) */
  1123. pitch <<= bppshift; /* -> bytes */
  1124.  
  1125. #ifdef SISVRAMQ
  1126. SiSSetupDSTColorDepth(pSiS->SiS310_AccelDepth);
  1127. switch(op) {
  1128. case PictOpClear:
  1129. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  1130. case PictOpDisjointClear:
  1131. case PictOpConjointClear:
  1132. #endif
  1133. SiSSetupPATFGDSTRect(0, pSiS->scrnOffset, DEV_HEIGHT)
  1134. /* SiSSetupROP(0x00) - is already zero */
  1135. SiSSetupCMDFlag(PATFG)
  1136. docopy = FALSE;
  1137. break;
  1138. case PictOpSrc:
  1139. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  1140. case PictOpDisjointSrc:
  1141. case PictOpConjointSrc:
  1142. #endif
  1143. SiSSetupSRCPitchDSTRect(pitch, pSiS->scrnOffset, DEV_HEIGHT);
  1144. SiSSetupAlpha(0xff)
  1145. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_NODESTALPHA)
  1146. break;
  1147. case PictOpDst:
  1148. #if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,2,0,0,0)
  1149. case PictOpDisjointDst:
  1150. case PictOpConjointDst:
  1151. #endif
  1152. SiSSetupSRCPitchDSTRect(pitch, pSiS->scrnOffset, DEV_HEIGHT);
  1153. SiSSetupAlpha(0x00)
  1154. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_CONSTANTALPHA)
  1155. docopy = FALSE;
  1156. break;
  1157. case PictOpOver:
  1158. SiSSetupSRCPitchDSTRect(pitch, pSiS->scrnOffset, DEV_HEIGHT);
  1159. SiSSetupAlpha(0x00)
  1160. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_PERPIXELALPHA)
  1161. break;
  1162. default:
  1163. return FALSE;
  1164. }
  1165. SiSSyncWP
  1166. #else
  1167. SiSSetupDSTColorDepth(pSiS->DstColor);
  1168. SiSSetupSRCPitch(pitch);
  1169. SiSSetupDSTRect(pSiS->scrnOffset, DEV_HEIGHT)
  1170. SiSSetupAlpha(0x00)
  1171. SiSSetupCMDFlag(ALPHA_BLEND | SRCVIDEO | A_PERPIXELALPHA | pSiS->SiS310_AccelDepth)
  1172. #endif
  1173. SiSReleaseCmdQue(pSiS);
  1174. /* Don't need source for clear and dest */
  1175. if(!docopy) return TRUE;
  1176.  
  1177. dst = (CARD8*)(pSiS->FbBase + (pSiS->AccelLinearScratch->offset << sbppshift));
  1178.  
  1179. if(pSiS->alphaBlitBusy) {
  1180. pSiS->alphaBlitBusy = FALSE;
  1181. SiSIdle
  1182. }
  1183.  
  1184. while(height--) {
  1185. memcpy(dst, texPtr, width);
  1186. texPtr += texPitch;
  1187. dst += pitch;
  1188. }
  1189.  
  1190. return TRUE;
  1191. }
  1192.  
  1193. static void
  1194. SiSSubsequentCPUToScreenTexture(ScrnInfoPtr pScrn,
  1195. int dst_x, int dst_y,
  1196. int src_x, int src_y,
  1197. int width, int height)
  1198. {
  1199. SISPtr pSiS = SISPTR(pScrn);
  1200. CARD32 srcbase, dstbase;
  1201.  
  1202. srcbase = pSiS->AccelLinearScratch->offset << 1;
  1203. if(pScrn->bitsPerPixel == 32) srcbase <<= 1;
  1204.  
  1205. #ifdef ACCELDEBUG
  1206. xf86DrvMsg(0, X_INFO, "FIRE: scrbase %x dx %d dy %d w %d h %d\n",
  1207. srcbase, dst_x, dst_y, width, height);
  1208. #endif
  1209.  
  1210. dstbase = 0;
  1211. if((dst_y >= pScrn->virtualY) || (dst_y >= 2048)) {
  1212. dstbase = pSiS->scrnOffset * dst_y;
  1213. dst_y = 0;
  1214. }
  1215.  
  1216. srcbase += FBOFFSET;
  1217. dstbase += FBOFFSET;
  1218.  
  1219. SiSOccpyCmdQue(pSiS);
  1220. #ifdef SISVRAMQ
  1221. SiSCheckQueue(16 * 3)
  1222. if(pSiS->ChipType == SIS_770)
  1223. SiSSetupSafeReg(0x26a90000)
  1224. SiSSetupSRCDSTBase(srcbase,dstbase);
  1225. SiSSetupSRCDSTXY(src_x, src_y, dst_x, dst_y)
  1226. SiSSetRectDoCMD(width,height)
  1227. #else
  1228. SiSSetupSRCBase(srcbase);
  1229. SiSSetupDSTBase(dstbase);
  1230. SiSSetupRect(width, height)
  1231. SiSSetupSRCXY(src_x, src_y)
  1232. SiSSetupDSTXY(dst_x, dst_y)
  1233. SiSDoCMD
  1234. #endif
  1235. SiSReleaseCmdQue(pSiS);
  1236.  
  1237. pSiS->alphaBlitBusy = TRUE;
  1238. }
  1239. #endif /* RENDER && INCL_RENDER */
  1240.  
  1241. #endif /* XAA */
  1242.  
  1243. #ifdef SIS_USE_EXA /* ---------------------------- EXA -------------------------- */
  1244.  
  1245. static void
  1246. SiSEXASync(ScreenPtr pScreen, int marker)
  1247. {
  1248. SISPtr pSiS = SISPTR(xf86ScreenToScrn(pScreen));
  1249.  
  1250. SiSIdle
  1251. }
  1252.  
  1253. static Bool
  1254. SiSPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planemask, Pixel fg)
  1255. {
  1256. ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
  1257. SISPtr pSiS = SISPTR(pScrn);
  1258. CARD16 pitch;
  1259.  
  1260. /* Planemask not supported */
  1261. if((planemask & ((1 << pPixmap->drawable.depth) - 1)) !=
  1262. (1 << pPixmap->drawable.depth) - 1) {
  1263. return FALSE;
  1264. }
  1265.  
  1266. if((pPixmap->drawable.bitsPerPixel != 8) &&
  1267. (pPixmap->drawable.bitsPerPixel != 16) &&
  1268. (pPixmap->drawable.bitsPerPixel != 32))
  1269. return FALSE;
  1270.  
  1271. /* Check that the pitch matches the hardware's requirements. Should
  1272. * never be a problem due to pixmapPitchAlign and fbScreenInit.
  1273. */
  1274. if(((pitch = exaGetPixmapPitch(pPixmap)) & 3))
  1275. return FALSE;
  1276.  
  1277. if(pSiS->disablecolorkeycurrent || pSiS->nocolorkey) {
  1278. if((CARD32)fg == pSiS->colorKey) {
  1279. /* NOOP - does not work: Pixmap is not neccessarily in the frontbuffer */
  1280. /* alu = 5; */
  1281. /* Fill it black; better than blue anyway */
  1282. fg = 0;
  1283. }
  1284. }
  1285.  
  1286. SiSSetupDSTColorDepth((pPixmap->drawable.bitsPerPixel >> 4) << 16);
  1287. SiSCheckQueue(16 * 1);
  1288. SiSSetupPATFGDSTRect(fg, pitch, DEV_HEIGHT)
  1289. SiSSetupROP(SiSGetPatternROP(alu))
  1290. SiSSetupCMDFlag(PATFG)
  1291. SiSSyncWP
  1292.  
  1293. pSiS->fillDstBase = (CARD32)exaGetPixmapOffset(pPixmap) + FBOFFSET;
  1294.  
  1295. return TRUE;
  1296. }
  1297.  
  1298. static void
  1299. SiSSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
  1300. {
  1301. ScrnInfoPtr pScrn = xf86ScreenToScrn(pPixmap->drawable.pScreen);
  1302. SISPtr pSiS = SISPTR(pScrn);
  1303.  
  1304. /* SiSSetupCMDFlag(BITBLT) - BITBLT = 0 */
  1305.  
  1306. SiSCheckQueue(16 * 2)
  1307. SiSSetupDSTXYRect(x1, y1, x2-x1, y2-y1)
  1308. SiSSetupDSTBaseDoCMD(pSiS->fillDstBase)
  1309. }
  1310.  
  1311. static void
  1312. SiSDoneSolid(PixmapPtr pPixmap)
  1313. {
  1314. }
  1315.  
  1316. static Bool
  1317. SiSPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir, int ydir,
  1318. int alu, Pixel planemask)
  1319. {
  1320. ScrnInfoPtr pScrn = xf86ScreenToScrn(pDstPixmap->drawable.pScreen);
  1321. SISPtr pSiS = SISPTR(pScrn);
  1322. CARD32 srcbase, dstbase;
  1323. CARD16 srcpitch, dstpitch;
  1324.  
  1325. /* Planemask not supported */
  1326. if((planemask & ((1 << pSrcPixmap->drawable.depth) - 1)) !=
  1327. (1 << pSrcPixmap->drawable.depth) - 1) {
  1328. return FALSE;
  1329. }
  1330.  
  1331. if((pDstPixmap->drawable.bitsPerPixel != 8) &&
  1332. (pDstPixmap->drawable.bitsPerPixel != 16) &&
  1333. (pDstPixmap->drawable.bitsPerPixel != 32))
  1334. return FALSE;
  1335.  
  1336. /* Check that the pitch matches the hardware's requirements. Should
  1337. * never be a problem due to pixmapPitchAlign and fbScreenInit.
  1338. */
  1339. if((srcpitch = exaGetPixmapPitch(pSrcPixmap)) & 3)
  1340. return FALSE;
  1341. if((dstpitch = exaGetPixmapPitch(pDstPixmap)) & 3)
  1342. return FALSE;
  1343.  
  1344. srcbase = (CARD32)exaGetPixmapOffset(pSrcPixmap) + FBOFFSET;
  1345.  
  1346. dstbase = (CARD32)exaGetPixmapOffset(pDstPixmap) + FBOFFSET;
  1347.  
  1348. /* TODO: Will there eventually be overlapping blits?
  1349. * If so, good night. Then we must calculate new base addresses
  1350. * which are identical for source and dest, otherwise
  1351. * the chips direction-logic will fail. Certainly funny
  1352. * to re-calculate x and y then...
  1353. */
  1354.  
  1355. SiSSetupDSTColorDepth((pDstPixmap->drawable.bitsPerPixel >> 4) << 16);
  1356. SiSCheckQueue(16 * 3);
  1357. SiSSetupSRCPitchDSTRect(srcpitch, dstpitch, DEV_HEIGHT)
  1358. SiSSetupROP(SiSGetCopyROP(alu))
  1359. SiSSetupSRCDSTBase(srcbase, dstbase)
  1360. SiSSyncWP
  1361.  
  1362. return TRUE;
  1363. }
  1364.  
  1365. static void
  1366. SiSCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY, int width, int height)
  1367. {
  1368. ScrnInfoPtr pScrn = xf86ScreenToScrn(pDstPixmap->drawable.pScreen);
  1369. SISPtr pSiS = SISPTR(pScrn);
  1370.  
  1371. SiSCheckQueue(16 * 2);
  1372. SiSSetupSRCDSTXY(srcX, srcY, dstX, dstY)
  1373. SiSSetRectDoCMD(width, height)
  1374. }
  1375.  
  1376. static void
  1377. SiSDoneCopy(PixmapPtr pDstPixmap)
  1378. {
  1379. }
  1380.  
  1381. #ifdef SIS_HAVE_COMPOSITE
  1382. static Bool
  1383. SiSCheckComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture,
  1384. PicturePtr pDstPicture)
  1385. {
  1386. ScrnInfoPtr pScrn = xf86ScreenToScrn(pDstPicture->pDrawable->pScreen);
  1387. SISPtr pSiS = SISPTR(pScrn);
  1388.  
  1389. xf86DrvMsg(0, 0, "CC: %d Src %x (fi %d ca %d) Msk %x (%d %d) Dst %x (%d %d)\n",
  1390. op, pSrcPicture->format, pSrcPicture->filter, pSrcPicture->componentAlpha,
  1391. pMaskPicture ? pMaskPicture->format : 0x2011, pMaskPicture ? pMaskPicture->filter : -1,
  1392. pMaskPicture ? pMaskPicture->componentAlpha : -1,
  1393. pDstPicture->format, pDstPicture->filter, pDstPicture->componentAlpha);
  1394.  
  1395. if(pSrcPicture->transform || (pMaskPicture && pMaskPicture->transform) || pDstPicture->transform) {
  1396. xf86DrvMsg(0, 0, "CC: src tr %p msk %p dst %p !!!!!!!!!!!!!!!\n",
  1397. pSrcPicture->transform,
  1398. pMaskPicture ? pMaskPicture->transform : 0,
  1399. pDstPicture->transform);
  1400. }
  1401.  
  1402. return FALSE;
  1403. }
  1404.  
  1405. static Bool
  1406. SiSPrepareComposite(int op, PicturePtr pSrcPicture, PicturePtr pMaskPicture,
  1407. PicturePtr pDstPicture, PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
  1408. {
  1409. #if 0
  1410. ScrnInfoPtr pScrn = xf86ScreenToScrn(pDst->drawable.pScreen);
  1411. SISPtr pSiS = SISPTR(pScrn);
  1412. #endif
  1413. return FALSE;
  1414. }
  1415.  
  1416. static void
  1417. SiSComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY, int dstX, int dstY,
  1418. int width, int height)
  1419. {
  1420. #if 0
  1421. ScrnInfoPtr pScrn = xf86ScreenToScrn(pDst->drawable.pScreen);
  1422. SISPtr pSiS = SISPTR(pScrn);
  1423. #endif
  1424. }
  1425.  
  1426. static void
  1427. SiSDoneComposite(PixmapPtr pDst)
  1428. {
  1429. }
  1430. #endif
  1431.  
  1432. Bool
  1433. SiSUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src, int src_pitch)
  1434. {
  1435. ScrnInfoPtr pScrn = xf86ScreenToScrn(pDst->drawable.pScreen);
  1436. SISPtr pSiS = SISPTR(pScrn);
  1437. unsigned char *dst = pDst->devPrivate.ptr;
  1438. int dst_pitch = exaGetPixmapPitch(pDst);
  1439.  
  1440. (pSiS->SyncAccel)(pScrn);
  1441.  
  1442. if(pDst->drawable.bitsPerPixel < 8)
  1443. return FALSE;
  1444.  
  1445. dst += (x * pDst->drawable.bitsPerPixel / 8) + (y * src_pitch);
  1446. while(h--) {
  1447. SiSMemCopyToVideoRam(pSiS, dst, (unsigned char *)src,
  1448. (w * pDst->drawable.bitsPerPixel / 8));
  1449. src += src_pitch;
  1450. dst += dst_pitch;
  1451. }
  1452.  
  1453. return TRUE;
  1454. }
  1455.  
  1456. Bool
  1457. SiSUploadToScratch(PixmapPtr pSrc, PixmapPtr pDst)
  1458. {
  1459. ScrnInfoPtr pScrn = xf86ScreenToScrn(pSrc->drawable.pScreen);
  1460. SISPtr pSiS = SISPTR(pScrn);
  1461. unsigned char *src, *dst;
  1462. int src_pitch = exaGetPixmapPitch(pSrc);
  1463. int dst_pitch, size, w, h, bytes;
  1464.  
  1465. w = pSrc->drawable.width;
  1466. /*
  1467. #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(6,8,2,0,0)
  1468. dst_pitch = ((w * (pSrc->drawable.bitsPerPixel >> 3)) +
  1469. pSiS->EXADriverPtr->card.offscreenPitch - 1) &
  1470. ~(pSiS->EXADriverPtr->card.offscreenPitch - 1);
  1471. #elif XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,0,0,0,0)
  1472. dst_pitch = ((w * (pSrc->drawable.bitsPerPixel >> 3)) +
  1473. pSiS->EXADriverPtr->card.pixmapPitchAlign - 1) &
  1474. ~(pSiS->EXADriverPtr->card.pixmapPitchAlign - 1);
  1475. #else*/
  1476. dst_pitch = ((w * (pSrc->drawable.bitsPerPixel >> 3)) +
  1477. pSiS->EXADriverPtr->pixmapPitchAlign - 1) &
  1478. ~(pSiS->EXADriverPtr->pixmapPitchAlign - 1);
  1479.  
  1480. //#endif
  1481. size = dst_pitch * pSrc->drawable.height;
  1482.  
  1483. if(size > pSiS->exa_scratch->size)
  1484. return FALSE;
  1485. /*
  1486. #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(6,8,2,0,0)
  1487. pSiS->exa_scratch_next = (pSiS->exa_scratch_next +
  1488. pSiS->EXADriverPtr->card.offscreenByteAlign - 1) &
  1489. ~(pSiS->EXADriverPtr->card.offscreenByteAlign - 1);
  1490. #elif XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,0,0,0,0)
  1491. pSiS->exa_scratch_next = (pSiS->exa_scratch_next +
  1492. pSiS->EXADriverPtr->card.pixmapOffsetAlign - 1) &
  1493. ~(pSiS->EXADriverPtr->card.pixmapOffsetAlign - 1);
  1494. #else*/
  1495. pSiS->exa_scratch_next = (pSiS->exa_scratch_next +
  1496. pSiS->EXADriverPtr->pixmapOffsetAlign - 1) &
  1497. ~(pSiS->EXADriverPtr->pixmapOffsetAlign - 1);
  1498. //#endif
  1499. /*
  1500. #if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,0,0,0,0)
  1501. if(pSiS->exa_scratch_next + size >
  1502. pSiS->exa_scratch->offset + pSiS->exa_scratch->size) {
  1503. (pSiS->EXADriverPtr->accel.WaitMarker)(pSrc->drawable.pScreen, 0);
  1504. pSiS->exa_scratch_next = pSiS->exa_scratch->offset;
  1505. }
  1506. #else*/
  1507. if(pSiS->exa_scratch_next + size >
  1508. pSiS->exa_scratch->offset + pSiS->exa_scratch->size) {
  1509. (pSiS->EXADriverPtr->WaitMarker)(pSrc->drawable.pScreen, 0);
  1510. pSiS->exa_scratch_next = pSiS->exa_scratch->offset;
  1511. }
  1512. //#endif
  1513.  
  1514. memcpy(pDst, pSrc, sizeof(*pDst));
  1515. pDst->devKind = dst_pitch;
  1516.  
  1517. //#if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,0,0,0,0)
  1518. // pDst->devPrivate.ptr = pSiS->EXADriverPtr->card.memoryBase + pSiS->exa_scratch_next;
  1519. //#else
  1520. pDst->devPrivate.ptr = pSiS->EXADriverPtr->memoryBase + pSiS->exa_scratch_next;
  1521. //#endif
  1522.  
  1523. pSiS->exa_scratch_next += size;
  1524.  
  1525. src = pSrc->devPrivate.ptr;
  1526. src_pitch = exaGetPixmapPitch(pSrc);
  1527. dst = pDst->devPrivate.ptr;
  1528.  
  1529. bytes = (src_pitch < dst_pitch) ? src_pitch : dst_pitch;
  1530.  
  1531. h = pSrc->drawable.height;
  1532.  
  1533. (pSiS->SyncAccel)(pScrn);
  1534.  
  1535. while(h--) {
  1536. SiSMemCopyToVideoRam(pSiS, dst, src, size);
  1537. src += src_pitch;
  1538. dst += dst_pitch;
  1539. }
  1540.  
  1541. return TRUE;
  1542. }
  1543.  
  1544. Bool
  1545. SiSDownloadFromScreen(PixmapPtr pSrc, int x, int y, int w, int h, char *dst, int dst_pitch)
  1546. {
  1547. ScrnInfoPtr pScrn = xf86ScreenToScrn(pSrc->drawable.pScreen);
  1548. SISPtr pSiS = SISPTR(pScrn);
  1549. unsigned char *src = pSrc->devPrivate.ptr;
  1550. int src_pitch = exaGetPixmapPitch(pSrc);
  1551. int size = src_pitch < dst_pitch ? src_pitch : dst_pitch;
  1552.  
  1553. (pSiS->SyncAccel)(pScrn);
  1554.  
  1555. if(pSrc->drawable.bitsPerPixel < 8)
  1556. return FALSE;
  1557.  
  1558. src += (x * pSrc->drawable.bitsPerPixel / 8) + (y * src_pitch);
  1559. while(h--) {
  1560. SiSMemCopyFromVideoRam(pSiS, (unsigned char *)dst, src, size);
  1561. src += src_pitch;
  1562. dst += dst_pitch;
  1563. }
  1564.  
  1565. return TRUE;
  1566. }
  1567. #endif /* EXA */
  1568.  
  1569. /* Helper for xv video blitter and rotation */
  1570.  
  1571. void
  1572. SISWriteBlitPacket(SISPtr pSiS, CARD32 *packet)
  1573. {
  1574. CARD32 dummybuf;
  1575.  
  1576. SiSWritePacketPart(packet[0], packet[1], packet[2], packet[3]);
  1577. SiSWritePacketPart(packet[4], packet[5], packet[6], packet[7]);
  1578. SiSWritePacketPart(packet[8], packet[9], packet[10], packet[11]);
  1579. SiSWritePacketPart(packet[12], packet[13], packet[14], packet[15]);
  1580. SiSWritePacketPart(packet[16], packet[17], packet[18], packet[19]);
  1581. SiSSyncWP;
  1582. (void)dummybuf; /* Suppress compiler warning */
  1583. }
  1584.  
  1585.  
  1586. /* For DGA usage */
  1587.  
  1588. static void
  1589. SiSDGAFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h, int color)
  1590. {
  1591. SiSSetupForSolidFill(pScrn, color, GXcopy, ~0);
  1592. SiSSubsequentSolidFillRect(pScrn, x, y, w, h);
  1593. }
  1594.  
  1595. static void
  1596. SiSDGABlitRect(ScrnInfoPtr pScrn, int srcx, int srcy, int dstx, int dsty, int w, int h, int color)
  1597. {
  1598. /* Don't need xdir, ydir */
  1599. SiSSetupForScreenToScreenCopy(pScrn, 0, 0, GXcopy, (CARD32)~0, color);
  1600. SiSSubsequentScreenToScreenCopy(pScrn, srcx, srcy, dstx, dsty, w, h);
  1601. }
  1602.  
  1603. /* Initialisation */
  1604.  
  1605. Bool
  1606. SiS315AccelInit(ScreenPtr pScreen)
  1607. {
  1608. ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
  1609. SISPtr pSiS = SISPTR(pScrn);
  1610. #ifdef SIS_USE_XAA
  1611. XAAInfoRecPtr infoPtr = NULL;
  1612. int topFB, reservedFbSize, usableFbSize;
  1613. BoxRec Avail;
  1614. #endif /* XAA */
  1615.  
  1616. pSiS->ColorExpandBufferNumber = 0;
  1617. pSiS->PerColorExpandBufferSize = 0;
  1618. pSiS->RenderAccelArray = NULL;
  1619. #ifdef SIS_USE_XAA
  1620. pSiS->AccelInfoPtr = NULL;
  1621. #endif
  1622. #ifdef SIS_USE_EXA
  1623. pSiS->EXADriverPtr = NULL;
  1624. pSiS->exa_scratch = NULL;
  1625. #endif
  1626.  
  1627. if((pScrn->bitsPerPixel != 8) &&
  1628. (pScrn->bitsPerPixel != 16) &&
  1629. (pScrn->bitsPerPixel != 32)) {
  1630. pSiS->NoAccel = TRUE;
  1631. }
  1632.  
  1633. if(!pSiS->NoAccel) {
  1634. #ifdef SIS_USE_XAA
  1635. if(!pSiS->useEXA) {
  1636. pSiS->AccelInfoPtr = infoPtr = XAACreateInfoRec();
  1637. if(!infoPtr) pSiS->NoAccel = TRUE;
  1638. }
  1639. #endif
  1640. #ifdef SIS_USE_EXA
  1641. if(pSiS->useEXA) {
  1642. if(!(pSiS->EXADriverPtr = xnfcalloc(sizeof(ExaDriverRec), 1))) {
  1643. pSiS->NoAccel = TRUE;
  1644. pSiS->NoXvideo = TRUE; /* No fbmem manager -> no xv */
  1645. }
  1646. }
  1647. #endif
  1648. }
  1649.  
  1650. if(!pSiS->NoAccel) {
  1651.  
  1652. SiSInitializeAccelerator(pScrn);
  1653.  
  1654. pSiS->InitAccel = SiSInitializeAccelerator;
  1655. pSiS->SyncAccel = SiSSyncAccel;
  1656. pSiS->FillRect = SiSDGAFillRect;
  1657. pSiS->BlitRect = SiSDGABlitRect;
  1658.  
  1659.  
  1660. #ifdef SIS_USE_XAA /* ----------------------- XAA ----------------------- */
  1661. if(!pSiS->useEXA) {
  1662.  
  1663. infoPtr->Flags = LINEAR_FRAMEBUFFER |
  1664. OFFSCREEN_PIXMAPS |
  1665. PIXMAP_CACHE;
  1666.  
  1667. /* sync */
  1668. infoPtr->Sync = SiSSync;
  1669.  
  1670. /* BitBlt */
  1671. infoPtr->SetupForScreenToScreenCopy = SiSSetupForScreenToScreenCopy;
  1672. infoPtr->SubsequentScreenToScreenCopy = SiSSubsequentScreenToScreenCopy;
  1673. infoPtr->ScreenToScreenCopyFlags = NO_PLANEMASK | TRANSPARENCY_GXCOPY_ONLY;
  1674.  
  1675. /* solid fills */
  1676. infoPtr->SetupForSolidFill = SiSSetupForSolidFill;
  1677. infoPtr->SubsequentSolidFillRect = SiSSubsequentSolidFillRect;
  1678. infoPtr->SolidFillFlags = NO_PLANEMASK;
  1679.  
  1680. /* solid line */
  1681. infoPtr->SetupForSolidLine = SiSSetupForSolidLine;
  1682. infoPtr->SubsequentSolidTwoPointLine = SiSSubsequentSolidTwoPointLine;
  1683. infoPtr->SubsequentSolidHorVertLine = SiSSubsequentSolidHorzVertLine;
  1684. infoPtr->SolidLineFlags = NO_PLANEMASK;
  1685.  
  1686. /* dashed line */
  1687. infoPtr->SetupForDashedLine = SiSSetupForDashedLine;
  1688. infoPtr->SubsequentDashedTwoPointLine = SiSSubsequentDashedTwoPointLine;
  1689. infoPtr->DashPatternMaxLength = 64;
  1690. infoPtr->DashedLineFlags = NO_PLANEMASK |
  1691. LINE_PATTERN_MSBFIRST_LSBJUSTIFIED;
  1692.  
  1693. /* 8x8 mono pattern fill */
  1694. infoPtr->SetupForMono8x8PatternFill = SiSSetupForMonoPatternFill;
  1695. infoPtr->SubsequentMono8x8PatternFillRect = SiSSubsequentMonoPatternFill;
  1696. infoPtr->Mono8x8PatternFillFlags = NO_PLANEMASK |
  1697. HARDWARE_PATTERN_SCREEN_ORIGIN |
  1698. HARDWARE_PATTERN_PROGRAMMED_BITS |
  1699. BIT_ORDER_IN_BYTE_MSBFIRST;
  1700.  
  1701.  
  1702.  
  1703. #ifdef SISVRAMQ
  1704. /* 8x8 color pattern fill (MMIO support not implemented) */
  1705. infoPtr->SetupForColor8x8PatternFill = SiSSetupForColor8x8PatternFill;
  1706. infoPtr->SubsequentColor8x8PatternFillRect = SiSSubsequentColor8x8PatternFillRect;
  1707. infoPtr->Color8x8PatternFillFlags = NO_PLANEMASK |
  1708. HARDWARE_PATTERN_SCREEN_ORIGIN |
  1709. NO_TRANSPARENCY;
  1710. #endif
  1711.  
  1712.  
  1713. #if defined(RENDER) && defined(INCL_RENDER)
  1714. /* Render */
  1715. SiSCalcRenderAccelArray(pScrn);
  1716. if(pSiS->RenderAccelArray) {
  1717. pSiS->AccelLinearScratch = NULL;
  1718.  
  1719. /* for sis671, we have not supported the render expansion */
  1720. #ifdef SISNEWRENDER
  1721. infoPtr->SetupForCPUToScreenAlphaTexture2 = (pSiS->ChipType == SIS_671)?
  1722. NULL/*SiSSetupForCPUToScreenAlphaTexture3D*/ : SiSSetupForCPUToScreenAlphaTexture;
  1723. infoPtr->CPUToScreenAlphaTextureDstFormats = (pScrn->bitsPerPixel == 16) ?
  1724. SiSDstTextureFormats16 : SiSDstTextureFormats32;
  1725. #else
  1726. infoPtr->SetupForCPUToScreenAlphaTexture = (pSiS->ChipType == SIS_671)?
  1727. SiSSetupForCPUToScreenAlphaTexture3D : SiSSetupForCPUToScreenAlphaTexture;
  1728.  
  1729. #endif
  1730. infoPtr->SubsequentCPUToScreenAlphaTexture = (pSiS->ChipType == SIS_671)?
  1731. NULL/*SiSSubsequentCPUToScreenTexture3D*/ : SiSSubsequentCPUToScreenTexture;
  1732. infoPtr->CPUToScreenAlphaTextureFormats = (pSiS->ChipType == SIS_671)?
  1733. NULL/*SiS3DAlphaTextureFormats*/ : SiSAlphaTextureFormats; /*3D accelerator needs a8r8g8b8 format*/
  1734. infoPtr->CPUToScreenAlphaTextureFlags = XAA_RENDER_NO_TILE;
  1735.  
  1736. #ifdef SISNEWRENDER
  1737. infoPtr->SetupForCPUToScreenTexture2 = (pSiS->ChipType == SIS_671)?
  1738. NULL/*SiSSubsequentCPUToScreenTexture3D*/ : SiSSetupForCPUToScreenTexture;
  1739. infoPtr->CPUToScreenTextureDstFormats = (pScrn->bitsPerPixel == 16) ?
  1740. SiSDstTextureFormats16 : SiSDstTextureFormats32;
  1741. #else
  1742. infoPtr->SetupForCPUToScreenTexture = (pSiS->ChipType == SIS_671)?
  1743. NULL/*SiSSubsequentCPUToScreenTexture3D*/ : SiSSetupForCPUToScreenTexture;
  1744. #endif
  1745. infoPtr->SubsequentCPUToScreenTexture = (pSiS->ChipType == SIS_671)?
  1746. NULL/*SiSSubsequentCPUToScreenTexture3D*/ : SiSSubsequentCPUToScreenTexture;
  1747. infoPtr->CPUToScreenTextureFormats = (pSiS->ChipType == SIS_671)?
  1748. NULL/*SiSSubsequentCPUToScreenTexture3D*/ : SiSTextureFormats;
  1749. infoPtr->CPUToScreenTextureFlags = (pSiS->ChipType == SIS_671)?
  1750. 0/*SiSSubsequentCPUToScreenTexture3D*/ : XAA_RENDER_NO_TILE;
  1751.  
  1752. }
  1753. #endif /* RENDER && INCL_RENDER */
  1754.  
  1755. #ifdef SISDUALHEAD
  1756. if(pSiS->DualHeadMode) {
  1757. infoPtr->RestoreAccelState = SiSRestoreAccelState;
  1758. }
  1759. #endif
  1760. } /* !EXA */
  1761. #endif /* XAA */
  1762.  
  1763. #ifdef SIS_USE_EXA /* ----------------------- EXA ----------------------- */
  1764. if(pSiS->useEXA) {
  1765. #if 0
  1766. //#if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,0,0,0,0)
  1767.  
  1768. int obase = 0;
  1769.  
  1770. /* data */
  1771. pSiS->EXADriverPtr->card.memoryBase = pSiS->FbBase;
  1772. pSiS->EXADriverPtr->card.memorySize = pSiS->maxxfbmem;
  1773.  
  1774. if(!obase) {
  1775. obase = pScrn->displayWidth * pScrn->virtualY * (pScrn->bitsPerPixel >> 3);
  1776. }
  1777.  
  1778. pSiS->EXADriverPtr->card.offScreenBase = obase;
  1779. if(pSiS->EXADriverPtr->card.memorySize > pSiS->EXADriverPtr->card.offScreenBase) {
  1780. pSiS->EXADriverPtr->card.flags = EXA_OFFSCREEN_PIXMAPS;
  1781. } else {
  1782. pSiS->NoXvideo = TRUE;
  1783. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  1784. "Not enough video RAM for offscreen memory manager. Xv disabled\n");
  1785. }
  1786.  
  1787. #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(6,8,2,0,0)
  1788. pSiS->EXADriverPtr->card.offscreenByteAlign = 16; /* src/dst: double quad word boundary */
  1789. pSiS->EXADriverPtr->card.offscreenPitch = 4; /* pitch: double word boundary */
  1790. #else
  1791. pSiS->EXADriverPtr->card.pixmapOffsetAlign = 16; /* src/dst: double quad word boundary */
  1792. pSiS->EXADriverPtr->card.pixmapPitchAlign = 4; /* pitch: double word boundary */
  1793. #endif
  1794. pSiS->EXADriverPtr->card.maxX = 4095;
  1795. pSiS->EXADriverPtr->card.maxY = 4095;
  1796.  
  1797. /* Sync */
  1798. pSiS->EXADriverPtr->accel.WaitMarker = SiSEXASync;
  1799.  
  1800. /* Solid fill */
  1801. pSiS->EXADriverPtr->accel.PrepareSolid = SiSPrepareSolid;
  1802. pSiS->EXADriverPtr->accel.Solid = SiSSolid;
  1803. pSiS->EXADriverPtr->accel.DoneSolid = SiSDoneSolid;
  1804.  
  1805. /* Copy */
  1806. pSiS->EXADriverPtr->accel.PrepareCopy = SiSPrepareCopy;
  1807. pSiS->EXADriverPtr->accel.Copy = SiSCopy;
  1808. pSiS->EXADriverPtr->accel.DoneCopy = SiSDoneCopy;
  1809.  
  1810. /* Composite */
  1811. #ifdef SIS_HAVE_COMPOSITE
  1812. SiSCalcRenderAccelArray(pScrn);
  1813. if(pSiS->RenderAccelArray) {
  1814. pSiS->EXADriverPtr->accel.CheckComposite = SiSCheckComposite;
  1815. pSiS->EXADriverPtr->accel.PrepareComposite = SiSPrepareComposite;
  1816. pSiS->EXADriverPtr->accel.Composite = SiSComposite;
  1817. pSiS->EXADriverPtr->accel.DoneComposite = SiSDoneComposite;
  1818. }
  1819. #endif
  1820.  
  1821. /* Upload, download to/from Screen */
  1822. pSiS->EXADriverPtr->accel.UploadToScreen = SiSUploadToScreen;
  1823. pSiS->EXADriverPtr->accel.DownloadFromScreen = SiSDownloadFromScreen;
  1824.  
  1825. #else /*Xorg>= 7.0*/
  1826.  
  1827. pSiS->EXADriverPtr->exa_major = 2;
  1828. pSiS->EXADriverPtr->exa_minor = 0;
  1829.  
  1830. /* data */
  1831. pSiS->EXADriverPtr->memoryBase = pSiS->FbBase;
  1832. pSiS->EXADriverPtr->memorySize = pSiS->maxxfbmem;
  1833. pSiS->EXADriverPtr->offScreenBase = pScrn->virtualX * pScrn->virtualY
  1834. * ((pScrn->bitsPerPixel + 7) / 8);
  1835. if(pSiS->EXADriverPtr->memorySize > pSiS->EXADriverPtr->offScreenBase) {
  1836. pSiS->EXADriverPtr->flags = EXA_OFFSCREEN_PIXMAPS;
  1837. } else {
  1838. pSiS->NoXvideo = TRUE;
  1839. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  1840. "Not enough video RAM for offscreen memory manager. Xv disabled\n");
  1841. }
  1842. pSiS->EXADriverPtr->pixmapOffsetAlign = 16; /* src/dst: double quad word boundary */
  1843. pSiS->EXADriverPtr->pixmapPitchAlign = 4; /* pitch: double word boundary */
  1844. pSiS->EXADriverPtr->maxX = 4095;
  1845. pSiS->EXADriverPtr->maxY = 4095;
  1846.  
  1847. /* Sync */
  1848. pSiS->EXADriverPtr->WaitMarker = SiSEXASync;
  1849.  
  1850. /* Solid fill */
  1851. pSiS->EXADriverPtr->PrepareSolid = SiSPrepareSolid;
  1852. pSiS->EXADriverPtr->Solid = SiSSolid;
  1853. pSiS->EXADriverPtr->DoneSolid = SiSDoneSolid;
  1854.  
  1855. /* Copy */
  1856. pSiS->EXADriverPtr->PrepareCopy = SiSPrepareCopy;
  1857. pSiS->EXADriverPtr->Copy = SiSCopy;
  1858. pSiS->EXADriverPtr->DoneCopy = SiSDoneCopy;
  1859.  
  1860. /* Composite */
  1861. #ifdef SIS_HAVE_COMPOSITE
  1862. SiSCalcRenderAccelArray(pScrn);
  1863. if(pSiS->RenderAccelArray) {
  1864. pSiS->EXADriverPtr->CheckComposite = SiSCheckComposite;
  1865. pSiS->EXADriverPtr->PrepareComposite = SiSPrepareComposite;
  1866. pSiS->EXADriverPtr->Composite = SiSComposite;
  1867. pSiS->EXADriverPtr->DoneComposite = SiSDoneComposite;
  1868. }
  1869. #endif
  1870.  
  1871. /* Upload, download to/from Screen */
  1872. pSiS->EXADriverPtr->UploadToScreen = SiSUploadToScreen;
  1873. pSiS->EXADriverPtr->DownloadFromScreen = SiSDownloadFromScreen;
  1874. #endif /*end of Xorg>=7.0*/
  1875.  
  1876. }
  1877. #endif /*end of EXA accelation*/
  1878. } /* NoAccel */
  1879.  
  1880. /* Init framebuffer memory manager */
  1881.  
  1882. /* Traditional layout:
  1883. * |-----------------++++++++++++++++++++^************==========~~~~~~~~~~~~|
  1884. * | UsableFbSize ColorExpandBuffers | DRI-Heap HWCursor CommandQueue
  1885. * FbBase topFB
  1886. * +-------------maxxfbmem---------------+
  1887. *
  1888. * On SiS76x with UMA+LFB:
  1889. * |UUUUUUUUUUUUUUU--------------++++++++++++++++++++^==========~~~~~~~~~~~~|
  1890. * DRI heap |UsableFbSize ColorExpandBuffers | HWCursor CommandQueue
  1891. * (in UMA and FbBase topFB
  1892. * eventually +---------- maxxfbmem ------------+
  1893. * beginning of
  1894. * LFB)
  1895. */
  1896.  
  1897. #ifdef SIS_USE_XAA
  1898. if(!pSiS->useEXA) {
  1899. topFB = pSiS->maxxfbmem; /* relative to FbBase */
  1900.  
  1901. reservedFbSize = pSiS->ColorExpandBufferNumber * pSiS->PerColorExpandBufferSize;
  1902.  
  1903.  
  1904. usableFbSize = topFB - reservedFbSize;
  1905. Avail.x1 = 0;
  1906. Avail.y1 = 0;
  1907. Avail.x2 = pScrn->displayWidth;
  1908. Avail.y2 = (usableFbSize / (pScrn->displayWidth * pScrn->bitsPerPixel / 8)) - 1;
  1909.  
  1910.  
  1911. if(Avail.y2 < 0) Avail.y2 = 32767;
  1912. if(Avail.y2 < pScrn->currentMode->VDisplay) {
  1913. xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
  1914. "Not enough video RAM for accelerator. "
  1915. "%dKB needed, %dKB available\n",
  1916. ((((pScrn->displayWidth * pScrn->bitsPerPixel / 8) /* +8 for make it sure */
  1917. * pScrn->currentMode->VDisplay) + reservedFbSize) / 1024) + 8,
  1918. pSiS->maxxfbmem/1024);
  1919. pSiS->NoAccel = TRUE;
  1920. pSiS->NoXvideo = TRUE;
  1921. XAADestroyInfoRec(pSiS->AccelInfoPtr);
  1922. pSiS->AccelInfoPtr = NULL;
  1923. return FALSE; /* Don't even init fb manager */
  1924. }
  1925.  
  1926. xf86DrvMsg(pScrn->scrnIndex, X_INFO,
  1927. "Framebuffer from (%d,%d) to (%d,%d)\n",
  1928. Avail.x1, Avail.y1, Avail.x2 - 1, Avail.y2 - 1);
  1929.  
  1930.  
  1931. xf86InitFBManager(pScreen, &Avail);
  1932.  
  1933.  
  1934. if(!pSiS->NoAccel) {
  1935. return XAAInit(pScreen, infoPtr);
  1936. }
  1937. } /* !EXA */
  1938. #endif /* XAA */
  1939.  
  1940. #ifdef SIS_USE_EXA
  1941. if(pSiS->useEXA) {
  1942.  
  1943. if(!pSiS->NoAccel) {
  1944.  
  1945. if(!exaDriverInit(pScreen, pSiS->EXADriverPtr)) {
  1946. pSiS->NoAccel = TRUE;
  1947. pSiS->NoXvideo = TRUE; /* No fbmem manager -> no xv */
  1948. return FALSE;
  1949. }
  1950.  
  1951. /* Reserve locked offscreen scratch area of 128K for glyph data */
  1952. pSiS->exa_scratch = exaOffscreenAlloc(pScreen, 128 * 1024, 16, TRUE,
  1953. SiSScratchSave, pSiS);
  1954. if(pSiS->exa_scratch) {
  1955. pSiS->exa_scratch_next = pSiS->exa_scratch->offset;
  1956. //#if XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(7,0,0,0,0)
  1957. // pSiS->EXADriverPtr->accel.UploadToScratch = SiSUploadToScratch;
  1958. //#else
  1959. pSiS->EXADriverPtr->UploadToScratch = SiSUploadToScratch;
  1960. //#endif
  1961. }
  1962.  
  1963. } else {
  1964.  
  1965. pSiS->NoXvideo = TRUE; /* No fbmem manager -> no xv */
  1966.  
  1967. }
  1968.  
  1969. }
  1970. #endif /* EXA */
  1971.  
  1972. return TRUE;
  1973. }
RAW Paste Data