1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/tdfx/tdfx_accel.c,v 1.14 2000/08/25 16:25:36 tsi Exp $ */
/* All drivers should typically include these */
#include "xf86.h"
#include "xf86_OSproc.h"
#include "xf86_ansic.h"
#include "compiler.h"
/* Drivers that need to access the PCI config space directly need this */
#include "xf86Pci.h"
/* Drivers for PCI hardware need this */
#include "xf86PciInfo.h"
/* Drivers that use XAA need this */
#include "xaa.h"
#include "xaalocal.h"
#include "xf86fbman.h"
#include "miline.h"
#include "tdfx.h"
#ifdef TDFX_DEBUG_CMDS
static int cmdCnt=0;
static int lastAddr=0;
#endif
static int TDFXROPCvt[] = {0x00, 0x88, 0x44, 0xCC, 0x22, 0xAA, 0x66, 0xEE,
0x11, 0x99, 0x55, 0xDD, 0x33, 0xBB, 0x77, 0xFF,
0x00, 0xA0, 0x50, 0xF0, 0x0A, 0xAA, 0x5A, 0xFA,
0x05, 0xA5, 0x55, 0xF5, 0x0F, 0xAF, 0x5F, 0xFF};
#define ROP_PATTERN_OFFSET 16
static void TDFXSetClippingRectangle(ScrnInfoPtr pScrn, int left, int top,
int right, int bottom);
static void TDFXDisableClipping(ScrnInfoPtr pScrn);
static void TDFXSetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int patx,
int paty, int fg, int bg, int rop,
unsigned int planemask);
static void TDFXSubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn, int patx,
int pay, int x, int y,
int w, int h);
static void TDFXSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop,
unsigned int planemask);
static void TDFXSubsequentSolidTwoPointLine(ScrnInfoPtr pScrn, int srcx,
int srcy, int dstx, int dsty,
int flags);
static void TDFXSubsequentSolidHorVertLine(ScrnInfoPtr pScrn, int x, int y,
int len, int dir);
static void TDFXNonTEGlyphRenderer(ScrnInfoPtr pScrn, int x, int y, int n,
NonTEGlyphPtr glyphs, BoxPtr pbox, int fg,
int rop, unsigned int planemask);
static void TDFXSetupForDashedLine(ScrnInfoPtr pScrn, int fg, int bg, int rop,
unsigned int planemask, int length,
unsigned char *pattern);
static void TDFXSubsequentDashedTwoPointLine(ScrnInfoPtr pScrn, int x1, int y1,
int x2, int y2, int flags,
int phase);
static void TDFXSetupForScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
int fg, int bg, int rop,
unsigned int planemask);
static void TDFXSubsequentScreenToScreenColorExpandFill(ScrnInfoPtr pScrn,
int x, int y, int w,
int h, int srcx,
int srcy, int offset);
static void TDFXSetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
int fg, int bg, int rop,
unsigned int planemask);
static void TDFXSubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn,
int x, int y,
int w, int h,
int skipleft);
static void TDFXSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno);
void
TDFXNeedSync(ScrnInfoPtr pScrn) {
TDFXPtr pTDFX = TDFXPTR(pScrn);
pTDFX->syncDone=FALSE;
pTDFX->AccelInfoRec->NeedToSync = TRUE;
}
void
TDFXFirstSync(ScrnInfoPtr pScrn) {
TDFXPtr pTDFX = TDFXPTR(pScrn);
if (!pTDFX->syncDone) {
#ifdef XF86DRI
if (pTDFX->directRenderingEnabled) {
DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
TDFXSwapContextPrivate(screenInfo.screens[pScrn->scrnIndex]);
}
#endif
pTDFX->syncDone=TRUE;
pTDFX->sync(pScrn);
}
}
void
TDFXCheckSync(ScrnInfoPtr pScrn) {
TDFXPtr pTDFX = TDFXPTR(pScrn);
if (pTDFX->syncDone) {
pTDFX->sync(pScrn);
pTDFX->syncDone=FALSE;
#ifdef XF86DRI
if (pTDFX->directRenderingEnabled) {
TDFXLostContext(screenInfo.screens[pScrn->scrnIndex]);
DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
}
#endif
}
}
void
TDFXSelectBuffer(TDFXPtr pTDFX, int which) {
int fmt;
TDFXMakeRoom(pTDFX, 4);
DECLARE(SSTCP_SRCBASEADDR|SSTCP_DSTBASEADDR|SSTCP_SRCFORMAT|SSTCP_DSTFORMAT);
switch (which) {
case TDFX_FRONT:
if (pTDFX->cpp==1) fmt=pTDFX->stride|(1<<16);
else fmt=pTDFX->stride|((pTDFX->cpp+1)<<16);
TDFXWriteLong(pTDFX, SST_2D_DSTBASEADDR, pTDFX->fbOffset);
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_SRCBASEADDR, pTDFX->fbOffset);
TDFXWriteLong(pTDFX, SST_2D_SRCFORMAT, fmt);
break;
case TDFX_BACK:
if (pTDFX->cpp==2)
fmt=((pTDFX->stride+127)/128)|(3<<16); /* Tiled 16bpp */
else
fmt=((pTDFX->stride+127)/128)|(5<<16); /* Tiled 32bpp */
TDFXWriteLong(pTDFX, SST_2D_DSTBASEADDR, pTDFX->backOffset|BIT(31));
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_SRCBASEADDR, pTDFX->backOffset|BIT(31));
TDFXWriteLong(pTDFX, SST_2D_SRCFORMAT, fmt);
break;
case TDFX_DEPTH:
if (pTDFX->cpp==2)
fmt=((pTDFX->stride+127)/128)|(3<<16); /* Tiled 16bpp */
else
fmt=((pTDFX->stride+127)/128)|(5<<16); /* Tiled 32bpp */
TDFXWriteLong(pTDFX, SST_2D_DSTBASEADDR, pTDFX->depthOffset|BIT(31));
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_SRCBASEADDR, pTDFX->depthOffset|BIT(31));
TDFXWriteLong(pTDFX, SST_2D_SRCFORMAT, fmt);
break;
default:
;
}
}
void
TDFXSetLFBConfig(TDFXPtr pTDFX) {
if (pTDFX->ChipType<=PCI_CHIP_VOODOO3) {
TDFXWriteLongMMIO(pTDFX, LFBMEMORYCONFIG, (pTDFX->backOffset>>12) |
SST_RAW_LFB_ADDR_STRIDE_4K |
((pTDFX->stride+127)/128)<<SST_RAW_LFB_TILE_STRIDE_SHIFT);
} else {
int chip;
int stride, bits;
if (pTDFX->cpp==2) stride=pTDFX->stride;
else stride=4*pTDFX->stride/pTDFX->cpp;
bits=pTDFX->backOffset>>12;
for (chip=0; chip<pTDFX->numChips; chip++) {
TDFXWriteChipLongMMIO(pTDFX, chip, LFBMEMORYCONFIG, (bits&0x1FFF) |
SST_RAW_LFB_ADDR_STRIDE_4K |
((bits&0x6000)<<10) |
((stride+127)/128)<<SST_RAW_LFB_TILE_STRIDE_SHIFT);
}
}
}
Bool
TDFXAccelInit(ScreenPtr pScreen)
{
XAAInfoRecPtr infoPtr;
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
TDFXPtr pTDFX = TDFXPTR(pScrn);
CARD32 commonFlags;
pTDFX->AccelInfoRec = infoPtr = XAACreateInfoRec();
if (!infoPtr) return FALSE;
infoPtr->Flags = PIXMAP_CACHE | OFFSCREEN_PIXMAPS | LINEAR_FRAMEBUFFER;
infoPtr->Sync = pTDFX->sync;
infoPtr->SetClippingRectangle = TDFXSetClippingRectangle;
infoPtr->DisableClipping = TDFXDisableClipping;
infoPtr->ClippingFlags = HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND |
HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY |
HARDWARE_CLIP_MONO_8x8_FILL |
HARDWARE_CLIP_COLOR_8x8_FILL |
HARDWARE_CLIP_SOLID_FILL |
HARDWARE_CLIP_DASHED_LINE |
HARDWARE_CLIP_SOLID_LINE;
miSetZeroLineBias(pScreen, OCTANT2 | OCTANT5 | OCTANT7 | OCTANT8);
commonFlags = BIT_ORDER_IN_BYTE_MSBFIRST | NO_PLANEMASK;
infoPtr->SetupForSolidFill = TDFXSetupForSolidFill;
infoPtr->SubsequentSolidFillRect = TDFXSubsequentSolidFillRect;
infoPtr->SolidFillFlags = commonFlags;
infoPtr->SetupForSolidLine = TDFXSetupForSolidLine;
infoPtr->SubsequentSolidTwoPointLine = TDFXSubsequentSolidTwoPointLine;
infoPtr->SubsequentSolidHorVertLine = TDFXSubsequentSolidHorVertLine;
infoPtr->SolidLineFlags = commonFlags;
infoPtr->SetupForDashedLine = TDFXSetupForDashedLine;
infoPtr->SubsequentDashedTwoPointLine = TDFXSubsequentDashedTwoPointLine;
infoPtr->DashedLineFlags = commonFlags | LINE_PATTERN_LSBFIRST_LSBJUSTIFIED;
infoPtr->DashPatternMaxLength = 32;
infoPtr->NonTEGlyphRenderer = TDFXNonTEGlyphRenderer;
infoPtr->NonTEGlyphRendererFlags = commonFlags;
infoPtr->SetupForScreenToScreenCopy = TDFXSetupForScreenToScreenCopy;
infoPtr->SubsequentScreenToScreenCopy = TDFXSubsequentScreenToScreenCopy;
infoPtr->ScreenToScreenCopyFlags = commonFlags;
#ifndef PROP_3DFX
/* We can use direct method because we're writing straight to the board */
infoPtr->SetupForCPUToScreenColorExpandFill =
TDFXSetupForCPUToScreenColorExpandFill;
infoPtr->SubsequentCPUToScreenColorExpandFill =
TDFXSubsequentCPUToScreenColorExpandFill;
infoPtr->ColorExpandBase = pTDFX->MMIOBase[0]+SST_2D_LAUNCH;
infoPtr->ColorExpandRange = 128;
infoPtr->CPUToScreenColorExpandFillFlags = commonFlags |
CPU_TRANSFER_PAD_DWORD | SCANLINE_PAD_DWORD |
LEFT_EDGE_CLIPPING; /* | LEFT_EDGE_CLIPPING_NEGATIVE_X; */
pTDFX->scanlineColorExpandBuffers[0]=0;
pTDFX->scanlineColorExpandBuffers[1]=0;
#else
/* When we're using the proprietary interface we have to use indirect */
pTDFX->scanlineColorExpandBuffers[0] = xalloc((pScrn->virtualX+62)/32*4);
pTDFX->scanlineColorExpandBuffers[1] = xalloc((pScrn->virtualX+62)/32*4);
infoPtr->NumScanlineColorExpandBuffers=2;
infoPtr->ScanlineColorExpandBuffers=pTDFX->scanlineColorExpandBuffers;
infoPtr->SetupForScanlineCPUToScreenColorExpandFill =
TDFXSetupForCPUToScreenColorExpandFill;
infoPtr->SubsequentScanlineCPUToScreenColorExpandFill =
TDFXSubsequentCPUToScreenColorExpandFill;
infoPtr->SubsequentColorExpandScanline =
TDFXSubsequentColorExpandScanline;
infoPtr->ScanlineCPUToScreenColorExpandFillFlags = commonFlags |
CPU_TRANSFER_PAD_DWORD | SCANLINE_PAD_DWORD |
LEFT_EDGE_CLIPPING; /* | LEFT_EDGE_CLIPPING_NEGATIVE_X; */
#endif
infoPtr->SetupForMono8x8PatternFill = TDFXSetupForMono8x8PatternFill;
infoPtr->SubsequentMono8x8PatternFillRect =
TDFXSubsequentMono8x8PatternFillRect;
infoPtr->Mono8x8PatternFillFlags = commonFlags |
HARDWARE_PATTERN_PROGRAMMED_BITS |
HARDWARE_PATTERN_PROGRAMMED_ORIGIN |
HARDWARE_PATTERN_SCREEN_ORIGIN;
#if 0
/* This causes us to fail compliance */
/* I suspect 1bpp pixmaps are getting written to cache incorrectly */
infoPtr->SetupForScreenToScreenColorExpandFill =
TDFXSetupForScreenToScreenColorExpandFill;
infoPtr->SubsequentScreenToScreenColorExpandFill =
TDFXSubsequentScreenToScreenColorExpandFill;
infoPtr->ScreenToScreenColorExpandFillFlags = commonFlags;
#endif
pTDFX->PciCnt=TDFXReadLongMMIO(pTDFX, 0)&0x1F;
pTDFX->PrevDrawState=pTDFX->DrawState=0;
pTDFX->ModeReg.srcbaseaddr=pTDFX->fbOffset;
TDFXWriteLongMMIO(pTDFX, SST_2D_SRCBASEADDR, pTDFX->ModeReg.srcbaseaddr);
pTDFX->ModeReg.dstbaseaddr=pTDFX->fbOffset;
TDFXWriteLongMMIO(pTDFX, SST_2D_DSTBASEADDR, pTDFX->ModeReg.dstbaseaddr);
/* Fill in acceleration functions */
return XAAInit(pScreen, infoPtr);
}
static void TDFXMakeRoomNoProp(TDFXPtr pTDFX, int size) {
int stat;
pTDFX->PciCnt-=size;
if (pTDFX->PciCnt<1) {
do {
stat=TDFXReadLongMMIO(pTDFX, 0);
pTDFX->PciCnt=stat&0x1F;
} while (pTDFX->PciCnt<size);
}
}
static void TDFXSendNOPNoProp(ScrnInfoPtr pScrn)
{
TDFXPtr pTDFX;
pTDFX=TDFXPTR(pScrn);
TDFXMakeRoomNoProp(pTDFX, 1);
TDFXWriteLongMMIO(pTDFX, SST_2D_COMMAND, SST_2D_NOP);
}
void TDFXSync(ScrnInfoPtr pScrn)
{
TDFXPtr pTDFX;
int i;
int stat;
TDFXTRACEACCEL("TDFXSync\n");
pTDFX=TDFXPTR(pScrn);
TDFXSendNOPNoProp(pScrn);
i=0;
do {
stat=TDFXReadLongMMIO(pTDFX, 0);
if (stat&SST_BUSY) i=0; else i++;
} while (i<3);
pTDFX->PciCnt=stat&0x1F;
}
static void
TDFXMatchState(TDFXPtr pTDFX)
{
if (pTDFX->PrevDrawState==pTDFX->DrawState) return;
/* Do we need to set a clipping rectangle? */
if (pTDFX->DrawState&DRAW_STATE_CLIPPING)
pTDFX->Cmd |= SST_2D_USECLIP1;
else
pTDFX->Cmd &= ~SST_2D_USECLIP1;
/* Do we need to set transparency? */
TDFXMakeRoom(pTDFX, 1);
DECLARE(SSTCP_COMMANDEXTRA);
if (pTDFX->DrawState&DRAW_STATE_TRANSPARENT) {
TDFXWriteLong(pTDFX, SST_2D_COMMANDEXTRA, SST_2D_SRC_COLORKEY_EX);
} else {
TDFXWriteLong(pTDFX, SST_2D_COMMANDEXTRA, 0);
}
/* Has the previous routine left clip1 changed? Reset it. */
if (pTDFX->DrawState&DRAW_STATE_CLIP1CHANGED) {
TDFXMakeRoom(pTDFX, 2);
DECLARE(SSTCP_CLIP1MIN|SSTCP_CLIP1MAX);
TDFXWriteLong(pTDFX, SST_2D_CLIP1MIN, pTDFX->ModeReg.clip1min);
TDFXWriteLong(pTDFX, SST_2D_CLIP1MAX, pTDFX->ModeReg.clip1max);
pTDFX->DrawState&=~DRAW_STATE_CLIP1CHANGED;
}
pTDFX->PrevDrawState=pTDFX->DrawState;
}
static void
TDFXClearState(ScrnInfoPtr pScrn)
{
TDFXPtr pTDFX;
pTDFX=TDFXPTR(pScrn);
pTDFX->Cmd=0;
pTDFX->DrawState&=~DRAW_STATE_TRANSPARENT;
/* Make sure we've done a sync */
TDFXFirstSync(pScrn);
}
static void
TDFXSetClippingRectangle(ScrnInfoPtr pScrn, int left, int top, int right,
int bottom)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSetClippingRectangle %d,%d to %d,%d\n", left, top,
right, bottom);
pTDFX=TDFXPTR(pScrn);
pTDFX->ModeReg.clip1min=(top&0xFFF)<<16 | (left&0xFFF);
pTDFX->ModeReg.clip1max=((bottom+1)&0xFFF)<<16 | ((right+1)&0xFFF);
pTDFX->DrawState|=DRAW_STATE_CLIPPING|DRAW_STATE_CLIP1CHANGED;
}
static void
TDFXDisableClipping(ScrnInfoPtr pScrn)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXDisableClippingRectangle\n");
pTDFX=TDFXPTR(pScrn);
pTDFX->DrawState&=~DRAW_STATE_CLIPPING;
}
void
TDFXSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, int ydir, int rop,
unsigned int planemask, int trans_color)
{
TDFXPtr pTDFX;
int fmt;
TDFXTRACEACCEL("TDFXSetupForScreenToScreenCopy\n xdir=%d ydir=%d "
"rop=%d planemask=%d trans_color=%d\n",
xdir, ydir, rop, planemask, trans_color);
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
if (trans_color!=-1) {
TDFXMakeRoom(pTDFX, 3);
DECLARE(SSTCP_SRCCOLORKEYMIN|SSTCP_SRCCOLORKEYMAX|SSTCP_ROP);
TDFXWriteLong(pTDFX, SST_2D_SRCCOLORKEYMIN, trans_color);
TDFXWriteLong(pTDFX, SST_2D_SRCCOLORKEYMAX, trans_color);
TDFXWriteLong(pTDFX, SST_2D_ROP, TDFXROPCvt[GXnoop]<<8);
pTDFX->DrawState|=DRAW_STATE_TRANSPARENT;
}
pTDFX->Cmd = (TDFXROPCvt[rop]<<24) | SST_2D_SCRNTOSCRNBLIT;
if (xdir==-1) pTDFX->Cmd |= SST_2D_X_RIGHT_TO_LEFT;
if (ydir==-1) pTDFX->Cmd |= SST_2D_Y_BOTTOM_TO_TOP;
if (pTDFX->cpp==1) fmt=pTDFX->stride|(1<<16);
else fmt=pTDFX->stride|((pTDFX->cpp+1)<<16);
TDFXMakeRoom(pTDFX, 2);
DECLARE(SSTCP_SRCFORMAT|SSTCP_DSTFORMAT);
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_SRCFORMAT, fmt);
}
void
TDFXSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, int srcX, int srcY,
int dstX, int dstY, int w, int h)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSubsequentScreenToScreenCopy\n srcX=%d srcY=%d"
" dstX=%d dstY=%d w=%d h=%d\n", srcX, srcY, dstX, dstY, w, h);
pTDFX=TDFXPTR(pScrn);
TDFXMatchState(pTDFX);
if (pTDFX->Cmd&SST_2D_Y_BOTTOM_TO_TOP) {
srcY += h-1;
dstY += h-1;
}
if (pTDFX->Cmd&SST_2D_X_RIGHT_TO_LEFT) {
srcX += w-1;
dstX += w-1;
}
if ((srcY>=dstY-32 && srcY<=dstY)||
(srcY>=pTDFX->prevBlitDest.y1-32 && srcY<=pTDFX->prevBlitDest.y1)) {
TDFXSendNOP(pScrn);
}
pTDFX->sync(pScrn);
TDFXMakeRoom(pTDFX, 4);
DECLARE(SSTCP_DSTSIZE|SSTCP_DSTXY|SSTCP_SRCXY|SSTCP_COMMAND);
TDFXWriteLong(pTDFX, SST_2D_SRCXY, (srcX&0x1FFF) | ((srcY&0x1FFF)<<16));
TDFXWriteLong(pTDFX, SST_2D_DSTSIZE, (w&0x1FFF) | ((h&0x1FFF)<<16));
TDFXWriteLong(pTDFX, SST_2D_DSTXY, (dstX&0x1FFF) | ((dstY&0x1FFF)<<16));
TDFXWriteLong(pTDFX, SST_2D_COMMAND, pTDFX->Cmd|SST_2D_GO);
pTDFX->prevBlitDest.y1=dstY;
}
void
TDFXSetupForSolidFill(ScrnInfoPtr pScrn, int color, int rop,
unsigned int planemask)
{
TDFXPtr pTDFX;
int fmt;
TDFXTRACEACCEL("TDFXSetupForSolidFill color=%d rop=%d planemask=%d\n",
color, rop, planemask);
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
pTDFX->Cmd=TDFXROPCvt[rop]<<24;
if (pTDFX->cpp==1) fmt=(1<<16)|pTDFX->stride;
else fmt=((pTDFX->cpp+1)<<16)|pTDFX->stride;
TDFXMakeRoom(pTDFX, 3);
DECLARE(SSTCP_DSTFORMAT|SSTCP_COLORFORE|
SSTCP_COLORBACK);
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_COLORBACK, color);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, color);
}
void
TDFXSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, int y, int w, int h)
{
/* Also called by TDFXSubsequentMono8x8PatternFillRect */
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSubsequentSolidFillRect x=%d y=%d w=%d h=%d\n",
x, y, w, h);
pTDFX=TDFXPTR(pScrn);
TDFXMatchState(pTDFX);
TDFXMakeRoom(pTDFX, 3);
DECLARE(SSTCP_DSTSIZE|SSTCP_DSTXY|SSTCP_COMMAND);
TDFXWriteLong(pTDFX, SST_2D_DSTSIZE, ((h&0x1FFF)<<16) | (w&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_DSTXY, ((y&0x1FFF)<<16) | (x&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_COMMAND, pTDFX->Cmd | SST_2D_RECTANGLEFILL |
SST_2D_GO);
}
static void
TDFXSetupForMono8x8PatternFill(ScrnInfoPtr pScrn, int patx, int paty,
int fg, int bg, int rop, unsigned int planemask)
{
TDFXPtr pTDFX;
int fmt;
TDFXTRACEACCEL("TDFXSetupForMono8x8PatternFill patx=%x paty=%x fg=%d"
" bg=%d rop=%d planemask=%d\n", patx, paty, fg, bg, rop,
planemask);
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
pTDFX->Cmd = (TDFXROPCvt[rop+ROP_PATTERN_OFFSET]<<24) |
SST_2D_MONOCHROME_PATTERN;
if (bg==-1) {
pTDFX->Cmd |= SST_2D_TRANSPARENT_MONOCHROME;
}
if (pTDFX->cpp==1) fmt=(1<<16)|pTDFX->stride;
else fmt=((pTDFX->cpp+1)<<16)|pTDFX->stride;
TDFXMakeRoom(pTDFX, 5);
DECLARE(SSTCP_DSTFORMAT|SSTCP_PATTERN0ALIAS
|SSTCP_PATTERN1ALIAS|SSTCP_COLORFORE|
SSTCP_COLORBACK);
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_PATTERN0, patx);
TDFXWriteLong(pTDFX, SST_2D_PATTERN1, paty);
TDFXWriteLong(pTDFX, SST_2D_COLORBACK, bg);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, fg);
}
static void
TDFXSubsequentMono8x8PatternFillRect(ScrnInfoPtr pScrn, int patx, int paty,
int x, int y, int w, int h)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSubsequentMono8x8PatternFillRect patx=%x paty=%x"
" x=%d y=%d w=%d h=%d\n", patx, paty, x, y, w, h);
pTDFX=TDFXPTR(pScrn);
pTDFX->Cmd |= ((patx&0x7)<<SST_2D_X_PATOFFSET_SHIFT) |
((paty&0x7)<<SST_2D_Y_PATOFFSET_SHIFT);
TDFXSubsequentSolidFillRect(pScrn, x, y, w, h);
}
static void
TDFXSetupForSolidLine(ScrnInfoPtr pScrn, int color, int rop,
unsigned int planemask)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSetupForSolidLine\n");
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
pTDFX->Cmd = (TDFXROPCvt[rop]<<24);
TDFXMakeRoom(pTDFX, 2);
DECLARE(SSTCP_COLORFORE|SSTCP_COLORBACK);
TDFXWriteLong(pTDFX, SST_2D_COLORBACK, color);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, color);
}
static void
TDFXSubsequentSolidTwoPointLine(ScrnInfoPtr pScrn, int srcx, int srcy,
int dstx, int dsty, int flags)
{
/* Also used by TDFXSubsequentDashedTwoPointLine */
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSubsequentSolidTwoPointLine "
"srcx=%d srcy=%d dstx=%d dsty=%d flags=%d\n",
srcx, srcy, dstx, dsty, flags);
pTDFX=TDFXPTR(pScrn);
TDFXMatchState(pTDFX);
if (flags&OMIT_LAST) pTDFX->Cmd|=SST_2D_POLYLINE;
else pTDFX->Cmd|=SST_2D_LINE;
TDFXMakeRoom(pTDFX, 3);
DECLARE(SSTCP_SRCXY|SSTCP_DSTXY|SSTCP_COMMAND);
TDFXWriteLong(pTDFX, SST_2D_SRCXY, (srcy&0x1FFF)<<16 | (srcx&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_DSTXY, (dsty&0x1FFF)<<16 | (dstx&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_COMMAND, pTDFX->Cmd|SST_2D_GO);
}
static void
TDFXSubsequentSolidHorVertLine(ScrnInfoPtr pScrn, int x, int y, int len,
int dir)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSubsequentSolidHorVertLine\n");
pTDFX=TDFXPTR(pScrn);
TDFXMatchState(pTDFX);
TDFXMakeRoom(pTDFX, 3);
DECLARE(SSTCP_SRCXY|SSTCP_DSTXY|SSTCP_COMMAND);
TDFXWriteLong(pTDFX, SST_2D_SRCXY, (y&0x1FFF)<<16 | (x&0x1FFF));
if (dir == DEGREES_0)
TDFXWriteLong(pTDFX, SST_2D_DSTXY, (y&0x1FFF)<<16 | ((x+len)&0x1FFF));
else
TDFXWriteLong(pTDFX, SST_2D_DSTXY, ((y+len)&0x1FFF)<<16 | (x&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_COMMAND, pTDFX->Cmd|SST_2D_POLYLINE|SST_2D_GO);
}
static void
TDFXNonTEGlyphRenderer(ScrnInfoPtr pScrn, int x, int y, int n,
NonTEGlyphPtr glyphs, BoxPtr pbox, int fg, int rop,
unsigned int planemask)
{
TDFXPtr pTDFX;
int ndwords;
int g;
NonTEGlyphPtr glyph;
TDFXTRACEACCEL("TDFXNonTEGlyphRenderer\n");
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
/* Don't bother fixing clip1, we're going to change it anyway */
pTDFX->DrawState&=~DRAW_STATE_CLIP1CHANGED;
TDFXMatchState(pTDFX);
/* We're changing clip1 so make sure we use it and flag it */
pTDFX->Cmd|=SST_2D_USECLIP1;
pTDFX->DrawState|=DRAW_STATE_CLIP1CHANGED;
pTDFX->Cmd|=(TDFXROPCvt[rop]<<24)|SST_2D_TRANSPARENT_MONOCHROME;
pTDFX->Cmd|=SST_2D_HOSTTOSCRNBLIT;
TDFXMakeRoom(pTDFX, 6);
DECLARE(SSTCP_CLIP1MIN|SSTCP_CLIP1MAX|SSTCP_SRCFORMAT|
SSTCP_SRCXY|SSTCP_COLORFORE|SSTCP_COMMAND);
TDFXWriteLong(pTDFX, SST_2D_CLIP1MIN, ((pbox->y1&0x1FFF)<<16) |
(pbox->x1&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_CLIP1MAX, ((pbox->y2&0x1FFF)<<16) |
(pbox->x2&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_SRCFORMAT, SST_2D_PIXFMT_1BPP |
SST_2D_SOURCE_PACKING_DWORD);
TDFXWriteLong(pTDFX, SST_2D_SRCXY, 0);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, fg);
TDFXWriteLong(pTDFX, SST_2D_COMMAND, pTDFX->Cmd);
for (g=0, glyph=glyphs; g<n; g++, glyph++) {
int dx = x+glyph->start;
int dy = y-glyph->yoff;
int w = glyph->end - glyph->start;
int *glyph_data = (int*)glyph->bits;
if (!glyph->srcwidth) continue;
ndwords = (glyph->srcwidth+3)>>2;
ndwords *= glyph->height;
TDFXMakeRoom(pTDFX, 2);
DECLARE(SSTCP_DSTSIZE|SSTCP_DSTXY);
TDFXWriteLong(pTDFX, SST_2D_DSTSIZE, ((glyph->height&0x1FFF)<<16) |
(w&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_DSTXY, ((dy&0x1FFF)<<16) | (dx&0x1FFF));
do {
int i = ndwords;
int j;
if (i>30) i=30;
TDFXMakeRoom(pTDFX, i);
DECLARE_LAUNCH(i, 0);
for (j=0; j<i; j++) {
TDFXWriteLong(pTDFX, SST_2D_LAUNCH, XAAReverseBitOrder(*glyph_data));
glyph_data++;
}
ndwords -= i;
} while (ndwords);
}
}
static void
TDFXSetupForDashedLine(ScrnInfoPtr pScrn, int fg, int bg, int rop,
unsigned int planemask, int length,
unsigned char *pattern)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSetupForDashedLine\n");
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
pTDFX->Cmd = (TDFXROPCvt[rop]<<24) | SST_2D_STIPPLE_LINE;
if(bg == -1) {
pTDFX->Cmd |= SST_2D_TRANSPARENT_MONOCHROME;
}
pTDFX->DashedLineSize = ((length-1)&0xFF)+1;
TDFXMakeRoom(pTDFX, 3);
DECLARE(SSTCP_COLORFORE|SSTCP_COLORBACK|SSTCP_LINESTIPPLE);
TDFXWriteLong(pTDFX, SST_2D_LINESTIPPLE, *(int *)pattern);
TDFXWriteLong(pTDFX, SST_2D_COLORBACK, bg);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, fg);
}
static void
TDFXSubsequentDashedTwoPointLine(ScrnInfoPtr pScrn, int x1, int y1,
int x2, int y2, int flags, int phase)
{
TDFXPtr pTDFX;
int linestyle;
TDFXTRACEACCEL("TDFXSubsequentDashedTwoPointLine\n");
pTDFX=TDFXPTR(pScrn);
linestyle = ((pTDFX->DashedLineSize-1)<<8) |
(((phase%pTDFX->DashedLineSize)&0x1F)<<24);
TDFXMakeRoom(pTDFX, 1);
DECLARE(SSTCP_LINESTYLE);
TDFXWriteLong(pTDFX, SST_2D_LINESTYLE, linestyle);
TDFXSubsequentSolidTwoPointLine(pScrn, x1, y1, x2, y2, flags);
}
static void
TDFXSetupForScreenToScreenColorExpandFill(ScrnInfoPtr pScrn, int fg, int bg,
int rop, unsigned int planemask)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("TDFXSetupForScreenToScreenColorExpandFill\n");
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
TDFXMatchState(pTDFX);
pTDFX->Cmd|=SST_2D_SCRNTOSCRNBLIT|(TDFXROPCvt[rop]<<24);
if (bg==-1) {
pTDFX->Cmd |= SST_2D_TRANSPARENT_MONOCHROME;
}
TDFXMakeRoom(pTDFX, 2);
DECLARE(SSTCP_COLORFORE|SSTCP_COLORBACK);
TDFXWriteLong(pTDFX, SST_2D_COLORBACK, bg);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, fg);
}
static void
TDFXSubsequentScreenToScreenColorExpandFill(ScrnInfoPtr pScrn, int x, int y,
int w, int h, int srcx, int srcy,
int offset)
{
TDFXPtr pTDFX;
int fmt;
TDFXTRACEACCEL("TDFXSubsequentScreenToScreenColorExpandFill "
"x=%d y=%d w=%d h=%d srcx=%d srcy=%d offset=%d\n",
x, y, w, h, srcx, srcy, offset);
pTDFX=TDFXPTR(pScrn);
/* Don't bother resetting clip1 since we're changing it anyway */
pTDFX->DrawState&=~DRAW_STATE_CLIP1CHANGED;
TDFXMatchState(pTDFX);
/* We're changing clip1 so make sure we use it and flag it */
pTDFX->Cmd|=SST_2D_USECLIP1;
pTDFX->DrawState|=DRAW_STATE_CLIP1CHANGED;
if (srcy>=pTDFX->prevBlitDest.y1-8 && srcy<=pTDFX->prevBlitDest.y1) {
TDFXSendNOP(pScrn);
}
if (pTDFX->cpp==1) fmt=(1<<16)|pTDFX->stride;
else fmt=(pTDFX->cpp+1)<<16|pTDFX->stride;
TDFXMakeRoom(pTDFX, 8);
DECLARE(SSTCP_SRCFORMAT|SSTCP_SRCXY|SSTCP_DSTFORMAT |
SSTCP_DSTSIZE|SSTCP_DSTXY|SSTCP_COMMAND |
SSTCP_CLIP1MIN|SSTCP_CLIP1MAX);
TDFXWriteLong(pTDFX,SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX,SST_2D_CLIP1MIN, (x&0x1FFF) | ((y&0x1FFF)<<16));
TDFXWriteLong(pTDFX,SST_2D_CLIP1MAX, ((x+w)&0x1FFF) | (((y+h)&0x1FFF)<<16));
TDFXWriteLong(pTDFX,SST_2D_SRCFORMAT, pTDFX->stride);
TDFXWriteLong(pTDFX,SST_2D_SRCXY, (srcx&0x1FFF) | ((srcy&0x1FFF)<<16));
TDFXWriteLong(pTDFX,SST_2D_DSTSIZE, ((w+offset)&0x1FFF) | ((h&0x1FFF)<<16));
TDFXWriteLong(pTDFX,SST_2D_DSTXY, ((x-offset)&0x1FFF) | ((y&0x1FFF)<<16));
TDFXWriteLong(pTDFX,SST_2D_COMMAND, pTDFX->Cmd|SST_2D_GO);
pTDFX->prevBlitDest.y1=y;
}
static void
TDFXSetupForCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, int fg, int bg,
int rop, unsigned int planemask)
{
TDFXPtr pTDFX;
TDFXTRACEACCEL("SetupForCPUToScreenColorExpandFill bg=%x fg=%x rop=%d\n",
bg, fg, rop);
pTDFX=TDFXPTR(pScrn);
TDFXClearState(pScrn);
pTDFX->Cmd|=SST_2D_HOSTTOSCRNBLIT|(TDFXROPCvt[rop]<<24);
if (bg == -1) {
pTDFX->Cmd |= SST_2D_TRANSPARENT_MONOCHROME;
}
TDFXMakeRoom(pTDFX, 2);
DECLARE(SSTCP_COLORBACK|SSTCP_COLORFORE);
TDFXWriteLong(pTDFX, SST_2D_COLORBACK, bg);
TDFXWriteLong(pTDFX, SST_2D_COLORFORE, fg);
}
static void
TDFXSubsequentCPUToScreenColorExpandFill(ScrnInfoPtr pScrn, int x, int y,
int w, int h, int skipleft)
{
TDFXPtr pTDFX;
int fmt;
TDFXTRACEACCEL("SubsequentCPUToScreenColorExpandFill x=%d y=%d w=%d h=%d"
" skipleft=%d\n", x, y, w, h, skipleft);
pTDFX = TDFXPTR(pScrn);
/* We're changing clip1 anyway, so don't bother to reset it */
pTDFX->DrawState&=~DRAW_STATE_CLIP1CHANGED;
TDFXMatchState(pTDFX);
/* Make sure we use clip1 and flag it */
pTDFX->Cmd|=SST_2D_USECLIP1;
pTDFX->DrawState|=DRAW_STATE_CLIP1CHANGED;
if (pTDFX->cpp==1) fmt=(1<<16)|pTDFX->stride;
else fmt=((pTDFX->cpp+1)<<16)|pTDFX->stride;
pTDFX->scanlineWidth=w;
TDFXMakeRoom(pTDFX, 8);
DECLARE(SSTCP_CLIP1MIN|SSTCP_CLIP1MAX|SSTCP_SRCFORMAT|
SSTCP_DSTFORMAT|SSTCP_DSTSIZE|SSTCP_SRCXY|
SSTCP_DSTXY|SSTCP_COMMAND);
TDFXWriteLong(pTDFX, SST_2D_DSTFORMAT, fmt);
TDFXWriteLong(pTDFX, SST_2D_CLIP1MIN, ((y&0x1FFF)<<16)|(x&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_CLIP1MAX, (((y+h)&0x1FFF)<<16)|((x+w)&0x1FFF));
TDFXWriteLong(pTDFX, SST_2D_SRCFORMAT, (((w+31)/32)*4) & 0x3FFF);
TDFXWriteLong(pTDFX, SST_2D_SRCXY, skipleft&0x1F);
TDFXWriteLong(pTDFX, SST_2D_DSTSIZE, ((w-skipleft)&0x1FFF)|((h&0x1FFF)<<16));
TDFXWriteLong(pTDFX, SST_2D_DSTXY, ((x+skipleft)&0x1FFF) | ((y&0x1FFF)<<16));
TDFXWriteLong(pTDFX, SST_2D_COMMAND, pTDFX->Cmd|SST_2D_GO);
}
static void TDFXSubsequentColorExpandScanline(ScrnInfoPtr pScrn, int bufno)
{
TDFXPtr pTDFX;
int i, size, cnt;
CARD32 *pos;
TDFXTRACEACCEL("SubsequentColorExpandScanline bufno=%d\n", bufno);
pTDFX = TDFXPTR(pScrn);
cnt=(pTDFX->scanlineWidth+31)/32;
pos=(CARD32 *)pTDFX->scanlineColorExpandBuffers[bufno];
while (cnt>0) {
if (cnt>64) size=64;
else size=cnt;
TDFXMakeRoom(pTDFX, size);
DECLARE_LAUNCH(size, 0);
for (i=0; i<size; i++, pos++) {
TDFXWriteLong(pTDFX, SST_2D_LAUNCH, *pos);
}
cnt-=size;
}
}
|