summaryrefslogtreecommitdiff
path: root/hw/kdrive/savage/s3draw.h
blob: 80b1b11506efa5fda863ee2be89dc3d5f062c7bf (plain)
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
/*
 * $Id$
 *
 * Copyright 1999 SuSE, Inc.
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of SuSE not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  SuSE makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 *
 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Author:  Keith Packard, SuSE, Inc.
 */
/* $XFree86: xc/programs/Xserver/hw/kdrive/savage/s3draw.h,v 1.1 1999/11/19 13:53:56 hohndel Exp $ */

#ifndef _S3DRAW_H_
#define _S3DRAW_H_

extern int  s3GCPrivateIndex;
extern int  s3WindowPrivateIndex;

typedef struct _s3Pattern {
    S3PatternCache    	*cache;
    int			id;
    PixmapPtr		pPixmap;
    int			fillStyle;
    int			xrot, yrot;
    unsigned int	fore, back;
} s3PatternRec, *s3PatternPtr;

typedef struct _s3PrivGC {
    int    	    type;	    /* type of drawable validated against */
    s3PatternPtr    pPattern;	    /* pattern */
} s3PrivGCRec, *s3PrivGCPtr;

#define s3GetGCPrivate(g)	    ((s3PrivGCPtr) \
			    (g)->devPrivates[s3GCPrivateIndex].ptr)

#define s3GCPrivate(g)	    s3PrivGCPtr s3Priv = s3GetGCPrivate(g)

#define s3GetWindowPrivate(w)    ((s3PatternPtr) \
			    (w)->devPrivates[s3WindowPrivateIndex].ptr)

#define s3SetWindowPrivate(w,p) (\
	    (w)->devPrivates[s3WindowPrivateIndex].ptr = (pointer) p)


void	_s3LoadPattern (ScreenPtr pScreen, s3PatternPtr pPattern);

#define SetupS3(s)  KdScreenPriv(s); \
		    s3CardInfo(pScreenPriv); \
		    S3Ptr s3 = s3c->s3

#ifdef S3_SYNC_DEBUG
#define SYNC_DEBUG()	fprintf (stderr, "Sync at %s:%d\n", __FILE__,__LINE__)
#else
#define SYNC_DEBUG()
#endif

#define S3_ASYNC
#ifdef S3_ASYNC
#define CheckSyncS3(s)		KdCheckSync(s)
#define MarkSyncS3(s)		KdMarkSync(s)
#define RegisterSync(screen)	KdScreenInitAsync (screen)
#else
#define CheckSyncS3(s3c)
#define MarkSyncS3(s3c)		_s3WaitIdleEmpty(s3c->s3)
#define RegisterSync(screen)	
#endif

#define WIDEN(x)    ((unsigned long) (x))
#define MERGE(a,b)  ((WIDEN(a) << 16) | WIDEN(b))

/*
 * Ok, so the S3 is broken -- it expects bitmaps to come MSB bit order,
 * but it's willing to take them in LSB byte order.  These macros
 * flip bits around without flipping bytes.  Instead of using a table
 * and burning memory bandwidth, do them in place with the CPU.
 */

/* The MIPS compiler automatically places these constants in registers */
#define S3InvertBits32(v) { \
    v = ((v & 0x55555555) << 1) | ((v >> 1) & 0x55555555); \
    v = ((v & 0x33333333) << 2) | ((v >> 2) & 0x33333333); \
    v = ((v & 0x0f0f0f0f) << 4) | ((v >> 4) & 0x0f0f0f0f); \
}

#define S3InvertBits16(v) { \
    v = ((v & 0x5555) << 1) | ((v >> 1) & 0x5555); \
    v = ((v & 0x3333) << 2) | ((v >> 2) & 0x3333); \
    v = ((v & 0x0f0f) << 4) | ((v >> 4) & 0x0f0f); \
}

#define S3InvertBits8(v) { \
    v = ((v & 0x55) << 1) | ((v >> 1) & 0x55); \
    v = ((v & 0x33) << 2) | ((v >> 2) & 0x33); \
    v = ((v & 0x0f) << 4) | ((v >> 4) & 0x0f); \
}

#define S3ByteSwap32(x)		((x) = (((x) >> 24) | \
					(((x) >> 8) & 0xff00) | \
					(((x) << 8) & 0xff0000) | \
					((x) << 24)))

#define S3ByteSwap16(x)		((x) = ((x) << 8) | ((x) >> 8))

#if BITMAP_BIT_ORDER == LSBFirst
#define S3AdjustBits32(x)	S3InvertBits32(x)
#define S3AdjustBits16(x)	S3InvertBits16(x)
#else
#define S3AdjustBits32(x)	S3ByteSwap32(x)
#define S3AdjustBits16(x)	S3ByteSwap16(x)
#endif

#define _s3WaitSlot(s3)		_s3WaitSlots(s3,1)

#define _s3SetFg(s3,_fg) { \
    DRAW_DEBUG ((DEBUG_REGISTERS, " fg <- 0x%x", _fg));\
    s3->fg = (_fg); \
}

#define _s3SetBg(s3,_bg) { \
    DRAW_DEBUG ((DEBUG_REGISTERS, " bg <- 0x%x", _bg));\
    s3->bg = (_bg); \
}

#define _s3SetWriteMask(s3,_mask) {\
    DRAW_DEBUG((DEBUG_REGISTERS," write_mask <- 0x%x", _mask)); \
    s3->write_mask = (_mask); \
}

#define _s3SetReadMask(s3,_mask) {\
    DRAW_DEBUG((DEBUG_REGISTERS," read_mask <- 0x%x", _mask)); \
    s3->read_mask = (_mask); \
}

#define _s3SetPixelControl(s3,_ctl) { \
    DRAW_DEBUG((DEBUG_REGISTERS, " pix_cntl <- 0x%x", PIX_CNTL | (_ctl))); \
    s3->pix_cntl_mult_misc2 = MERGE (CONTROL_MISC2, PIX_CNTL | (_ctl)); \
}

#define _s3SetFgMix(s3,_mix) { \
    DRAW_DEBUG((DEBUG_REGISTERS, " fg_mix <- 0x%x", _mix)); \
    s3->enh_fg_mix = (_mix); \
}
	       
#define _s3SetBgMix(s3,_mix) { \
    DRAW_DEBUG((DEBUG_REGISTERS, " bg_mix <- 0x%x", _mix)); \
    s3->enh_bg_mix = (_mix); \
}
	       
#define _s3SetMix(s3,fg_mix,bg_mix) { \
    DRAW_DEBUG((DEBUG_REGISTERS, " alt_mix <- 0x%x", MERGE(fg_mix,bg_mix))); \
    s3->alt_mix = MERGE(fg_mix,bg_mix); \
}

#define _s3SetCur(s3,_x,_y) { \
    DRAW_DEBUG ((DEBUG_REGISTERS, " alt_curxy <- 0x%x", MERGE(_x,_y))); \
    s3->alt_curxy = MERGE(_x,_y); \
}

#define _s3SetStep(s3,_x,_y) { \
    DRAW_DEBUG ((DEBUG_REGISTERS, " alt_step <- 0x%x", MERGE(_x,_y))); \
    s3->alt_step = MERGE(_x,_y); \
}
		 
#define _s3SetErr(s3,_e) { \
    DRAW_DEBUG ((DEBUG_REGISTERS, " err_term <- 0x%x", _e)); \
    s3->err_term = (_e); \
}
		 
#define _s3SetPcnt(s3,_x,_y) { \
    DRAW_DEBUG ((DEBUG_REGISTERS, " alt_pcnt <- 0x%x", MERGE(_x,_y))); \
    s3->alt_pcnt = MERGE(_x,_y); \
}
		 
#define _s3SetScissorsTl(s3,t,l) {\
    DRAW_DEBUG ((DEBUG_REGISTERS, " scissors_tl <- 0x%x", MERGE(t,l))); \
    s3->scissors_tl = MERGE(t,l); \
}

#define _s3SetScissorsBr(s3,b,r) {\
    DRAW_DEBUG ((DEBUG_REGISTERS, " scissors_br <- 0x%x", MERGE(b,r))); \
    s3->scissors_br = MERGE(b,r); \
}

#define _s3CmdWait(s3)

#define _s3SetCmd(s3,_cmd) { \
    DRAW_DEBUG((DEBUG_REGISTERS, " cmd <- 0x%x", _cmd)); \
    _s3CmdWait(s3); \
    s3->cmd_gp_stat = (_cmd); \
    /* { CARD32	__junk__; __junk__ = s3->cmd_gp_stat; } */ \
}
    
#define _s3SetSolidFill(s3,pix,alu,mask) { \
    DRAW_DEBUG((DEBUG_SET,"set fill 0x%x %d 0x%x",pix,alu,mask)); \
    _s3WaitSlots(s3,4); \
    _s3SetFg (s3, pix); \
    _s3SetWriteMask(s3,mask); \
    _s3SetMix (s3, FSS_FRGDCOL | s3alu[alu], BSS_BKGDCOL | MIX_SRC); \
    _s3SetPixelControl (s3, MIXSEL_FRGDMIX); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

#define _s3SolidRect(s3,x,y,w,h) {\
    DRAW_DEBUG((DEBUG_RENDER,"solid rect %d,%d %dx%d",x,y,w,h)); \
    _s3WaitSlots(s3,3); \
    _s3SetCur(s3, x, y); \
    _s3SetPcnt (s3, (w)-1, (h)-1); \
    _s3SetCmd (s3, CMD_RECT|INC_X|INC_Y|DRAW|WRTDATA); \
    DRAW_DEBUG((DEBUG_RENDER,"  done")); \
}

#define _s3SolidLine(s3,maj,min,len,cmd) { \
    DRAW_DEBUG ((DEBUG_RENDER, "solid line 0x%x 0x%x 0x%x", maj, min, cmd)); \
    _s3WaitSlots(s3,4); \
    _s3SetPcnt(s3, (len), 0); \
    _s3SetStep(s3, 2*((min) - (maj)), 2*(min)); \
    _s3SetErr(s3, 2*(min) - (maj)); \
    _s3SetCmd (s3, CMD_LINE | (cmd) | DRAW | WRTDATA); \
}

#define _s3ClipLine(s3,cmd,e1,e2,e,len) {\
    DRAW_DEBUG ((DEBUG_RENDER, "clip line 0x%x 0x%x 0x%x 0x%x 0x%x", cmd,e1,e2,e,len)); \
    _s3WaitSlots(s3, 4); \
    _s3SetPcnt (s3, (len), 0); \
    _s3SetStep (s3, e2, e1); \
    _s3SetErr (s3, e); \
    _s3SetCmd (s3, CMD_LINE | (cmd) | DRAW | WRTDATA); \
}

#define _s3SetTile(s3,alu,mask) { \
    DRAW_DEBUG ((DEBUG_SET,"set tile %d 0x%x", alu, mask)); \
    _s3WaitSlots(s3,3); \
    _s3SetWriteMask(s3, mask); \
    _s3SetMix(s3, FSS_BITBLT | s3alu[alu], BSS_BITBLT|s3alu[alu]); \
    _s3SetPixelControl (s3, MIXSEL_FRGDMIX); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

/*
 * For some reason, MIX_DST doesn't work in this mode; use MIX_OR with
 * an explicit 0 pixel value
 */
#define _s3SetStipple(s3,alu,mask,_fg) {\
    DRAW_DEBUG ((DEBUG_SET,"set stipple 0x%x %d 0x%x", _fg, alu, mask)); \
    _s3WaitSlots(s3,5); \
    _s3SetFg (s3, _fg); \
    _s3SetBg (s3, 0); \
    _s3SetWriteMask(s3,mask); \
    _s3SetMix (s3, FSS_FRGDCOL | s3alu[alu], BSS_BKGDCOL|MIX_OR); \
    _s3SetPixelControl (s3, MIXSEL_EXPBLT); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

#define _s3SetOpaqueStipple(s3,alu,mask,_fg,_bg) {\
    DRAW_DEBUG ((DEBUG_SET,"set opaque stipple 0x%x 0x%x %d 0x%x", _fg, _bg, alu, mask)); \
    _s3WaitSlots(s3,5); \
    _s3SetFg (s3, _fg); \
    _s3SetBg (s3, _bg); \
    _s3SetWriteMask(s3,mask); \
    _s3SetMix (s3, FSS_FRGDCOL | s3alu[alu], BSS_BKGDCOL|s3alu[alu]); \
    _s3SetPixelControl (s3, MIXSEL_EXPBLT); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

#define _s3PatRect(s3,px,py,x,y,w,h) {\
    DRAW_DEBUG ((DEBUG_RENDER, "pat rect %d,%d %dx%d", x,y,w,h)); \
    _s3WaitSlots(s3, 4); \
    _s3SetCur (s3, px, py); \
    _s3SetStep (s3, x, y); \
    _s3SetPcnt (s3, (w)-1, (h)-1); \
    _s3SetCmd (s3, CMD_PATBLT|INC_X|INC_Y|DRAW|PLANAR|WRTDATA); \
    DRAW_DEBUG((DEBUG_RENDER,"  done")); \
}

#define _s3SetBlt(s3,alu,mask) { \
    DRAW_DEBUG ((DEBUG_SET,"set blt %d 0x%x", alu, mask)); \
    _s3WaitSlots(s3,3); \
    _s3SetPixelControl (s3, MIXSEL_FRGDMIX); \
    _s3SetMix(s3, FSS_BITBLT | s3alu[alu], BSS_BITBLT | s3alu[alu]); \
    _s3SetWriteMask(s3, mask);  \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

#define _s3Blt(s3,_sx,_sy,_dx,_dy,_w,_h,_dir) { \
    DRAW_DEBUG ((DEBUG_RENDER, "blt %d,%d -> %d,%d %dx%d 0x%x", \
		_sx,_sy,_dx,_dy,_w,_h,_dir)); \
    _s3WaitSlots(s3,4); \
    _s3SetCur(s3,_sx,_sy); \
    _s3SetStep(s3,_dx,_dy); \
    _s3SetPcnt(s3,(_w)-1,(_h)-1); \
    _s3SetCmd (s3, CMD_BITBLT | (_dir) | DRAW | WRTDATA); \
    DRAW_DEBUG((DEBUG_RENDER,"  done")); \
}
    
#define _s3SetOpaquePlaneBlt(s3,alu,mask,_fg,_bg) {\
    DRAW_DEBUG ((DEBUG_SET,"set opaque plane blt 0x%x 0x%x %d 0x%x", \
		_fg, _bg, alu, mask)); \
    /* _s3WaitSlots(s3, 5); */ \
    _s3WaitIdleEmpty (s3); \
    _s3SetFg(s3,_fg); \
    _s3SetBg(s3,_bg); \
    _s3SetWriteMask(s3,mask); \
    _s3SetMix(s3,FSS_FRGDCOL|s3alu[alu], BSS_BKGDCOL|s3alu[alu]); \
    _s3SetPixelControl(s3,MIXSEL_EXPPC); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}
		       
#define _s3SetTransparentPlaneBlt(s3,alu,mask,_fg) {\
    DRAW_DEBUG ((DEBUG_SET,"set transparent plane blt 0x%x %d 0x%x", \
		_fg, alu, mask)); \
    /*_s3WaitSlots(s3, 4);  */ \
    _s3WaitIdleEmpty (s3); \
    _s3SetFg(s3,_fg); \
    _s3SetWriteMask(s3,mask); \
    _s3SetMix(s3,FSS_FRGDCOL|s3alu[alu], BSS_BKGDCOL|MIX_DST); \
    _s3SetPixelControl(s3,MIXSEL_EXPPC); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}
		       
/* Across the plane blt */
#define _s3PlaneBlt(s3,x,y,w,h) {\
    DRAW_DEBUG ((DEBUG_RENDER, "plane blt %d,%d %dx%d", x,y,w,h)); \
    _s3WaitSlots(s3, 4); \
    _s3SetPixelControl(s3,MIXSEL_EXPPC); \
    _s3SetCur(s3, x, y); \
    _s3SetPcnt (s3, (w)-1, (h)-1); \
    _s3SetCmd (s3, \
	       CMD_RECT|    /* Fill rectangle */ \
	       BYTSEQ|	    /* LSB byte order */ \
	       _32BIT|	    /* 32 bit data on 32 bit boundaries */ \
	       PCDATA|	    /* Data from CPU */ \
	       INC_X|INC_Y| /* X and Y both increasing */ \
	       DRAW|	    /* Draw, not move */ \
	       PLANAR|	    /* multi pixel */ \
	       WRTDATA); \
    DRAW_DEBUG((DEBUG_RENDER,"  done")); \
}

#define _s3SetClip(s3,pbox) {\
    DRAW_DEBUG ((DEBUG_SET, "set clip %dx%d -> %dx%d ", \
		pbox->x1, pbox->y1, pbox->x2, pbox->y2)); \
    _s3WaitSlots(s3, 2); \
    _s3SetScissorsTl(s3,(pbox)->x1, (pbox)->y1); \
    _s3SetScissorsBr(s3,(pbox)->x2 - 1, (pbox)->y2 - 1); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

#define _s3ResetClip(s3,pScreen) { \
    DRAW_DEBUG ((DEBUG_SET, "reset clip")); \
    _s3WaitSlots(s3, 2); \
    _s3SetScissorsTl(s3,0,0); \
    _s3SetScissorsBr(s3,pScreen->width - 1, pScreen->height - 1); \
    DRAW_DEBUG((DEBUG_SET,"  done")); \
}

RegionPtr
s3CopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
	   int srcx, int srcy, int width, int height, int dstx, int dsty);
    
RegionPtr
s3CopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
	    int srcx, int srcy, int width, int height, 
	    int dstx, int dsty, unsigned long bitPlane);
    
void
s3PushPixels (GCPtr pGC, PixmapPtr pBitmap,
	      DrawablePtr pDrawable,
	      int w, int h, int x, int y);

void
s3FillBoxSolid (DrawablePtr pDrawable, int nBox, BoxPtr pBox, 
		unsigned long pixel, int alu, unsigned long planemask);
    
void
s3FillBoxPattern (DrawablePtr pDrawable, int nBox, BoxPtr pBox, 
		  int alu, unsigned long planemask, s3PatternPtr pPattern);

void
s3PolyFillRect (DrawablePtr pDrawable, GCPtr pGC, 
		int nrectFill, xRectangle *prectInit);

void
s3FillSpans (DrawablePtr pDrawable, GCPtr pGC, int n, 
	     DDXPointPtr ppt, int *pwidth, int fSorted);
    
void
s3PolyFillArcSolid (DrawablePtr pDraw, GCPtr pGC, int narcs, xArc *parcs);

void
s3FillPoly1Rect (DrawablePtr pDrawable, GCPtr pGC, int shape, 
		 int mode, int count, DDXPointPtr ptsIn);

void
s3PolyGlyphBlt (DrawablePtr pDrawable, 
		GCPtr pGC, 
		int xInit, int y, 
		unsigned int nglyphInit,
		CharInfoPtr *ppciInit, 
		pointer pglyphBase);

void
s3ImageGlyphBlt (DrawablePtr pDrawable, 
		GCPtr pGC, 
		int x, int y, 
		unsigned int nglyph, 
		CharInfoPtr *ppci, 
		pointer pglyphBase);

void
s3ImageTEGlyphBlt (DrawablePtr pDrawable, GCPtr pGC,
		   int xInit, int y,
		   unsigned int nglyphInit,
		   CharInfoPtr *ppciInit,
		   pointer pglyphBase);

void
s3PolyTEGlyphBlt (DrawablePtr pDrawable, GCPtr pGC, 
		  int x, int y, 
		  unsigned int nglyph, CharInfoPtr *ppci,
		  pointer pglyphBase);

void
s3Polylines (DrawablePtr pDrawable, GCPtr pGC,
	     int mode, int nptInit, DDXPointPtr pptInit);

void
s3PolySegment (DrawablePtr pDrawable, GCPtr pGC, 
	       int nsegInit, xSegment *pSegInit);

void
s3FillBoxSolid (DrawablePtr pDrawable, int nBox, BoxPtr pBox, 
		unsigned long pixel, int alu, unsigned long planemask);

void	s3ValidateGC (GCPtr pGC, Mask changes, DrawablePtr pDrawable);

void
s3CheckGCFill (GCPtr pGC);

void
s3MoveGCFill (GCPtr pGC);

void
s3SyncProc (DrawablePtr pDrawable);

#endif