Chop out more dead code.
[mesa.git] / src / mesa / drivers / dri / sis / sis_span.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
5 All Rights Reserved.
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_span.c,v 1.5 2001/03/21 16:14:26 dawes Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
33 */
34
35 #include "sis_context.h"
36 #include "sis_span.h"
37 #include "sis_lock.h"
38 #include "sis_tris.h"
39
40 #include "swrast/swrast.h"
41
42 #define DBG 0
43
44 #define LOCAL_VARS \
45 sisContextPtr smesa = SIS_CONTEXT(ctx); \
46 char *buf = (char *)(smesa->FbBase + smesa->drawOffset); \
47 char *read_buf = (char *)(smesa->FbBase + smesa->readOffset); \
48 GLuint p; \
49 (void) read_buf; (void) buf; (void) p
50
51 #define LOCAL_DEPTH_VARS \
52 sisContextPtr smesa = SIS_CONTEXT(ctx); \
53 char *buf = smesa->depthbuffer; \
54
55 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
56
57 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
58 _y >= miny && _y < maxy)
59
60 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
61 if ( _y < miny || _y >= maxy ) { \
62 _n1 = 0, _x1 = x; \
63 } else { \
64 _n1 = _n; \
65 _x1 = _x; \
66 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
67 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
68 }
69
70 #define HW_LOCK() do {} while(0);
71
72 #define HW_CLIPLOOP() \
73 do { \
74 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
75 int _nc = dPriv->numClipRects; \
76 \
77 while ( _nc-- ) { \
78 int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \
79 int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \
80 int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \
81 int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
82
83 #define HW_ENDCLIPLOOP() \
84 } \
85 } while (0)
86
87 #define HW_UNLOCK() do {} while(0);
88
89 /* RGB565 */
90 #define INIT_MONO_PIXEL(p, color) \
91 p = SISPACKCOLOR565( color[0], color[1], color[2] )
92
93 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
94 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = \
95 (((r & 0xf8) << 8) | \
96 ((g & 0xfc) << 3) | \
97 (b >> 3))
98
99 #define WRITE_PIXEL( _x, _y, p ) \
100 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = p
101
102 #define READ_RGBA( rgba, _x, _y ) \
103 do { \
104 GLushort p = *(GLushort *)(read_buf + _x*2 + _y*smesa->readPitch); \
105 rgba[0] = (p & 0xf800) >> 8; \
106 rgba[1] = (p & 0x07e0) >> 3; \
107 rgba[2] = (p & 0x001f) << 3; \
108 rgba[3] = 0xff; \
109 } while(0)
110
111 #define TAG(x) sis##x##_565
112 #include "spantmp.h"
113
114
115 /* ARGB8888 */
116 #undef INIT_MONO_PIXEL
117 #define INIT_MONO_PIXEL(p, color) \
118 p = SISPACKCOLOR8888( color[0], color[1], color[2], color[3] )
119
120 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
121 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = \
122 (((a) << 24) | \
123 ((r) << 16) | \
124 ((g) << 8) | \
125 ((b)))
126
127 #define WRITE_PIXEL( _x, _y, p ) \
128 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = p
129
130 #define READ_RGBA( rgba, _x, _y ) \
131 do { \
132 GLuint p = *(GLuint *)(read_buf + _x*4 + _y*smesa->readPitch); \
133 rgba[0] = (p >> 16) & 0xff; \
134 rgba[1] = (p >> 8) & 0xff; \
135 rgba[2] = (p >> 0) & 0xff; \
136 rgba[3] = 0xff; \
137 } while(0)
138
139 #define TAG(x) sis##x##_8888
140 #include "spantmp.h"
141
142
143 /* 16 bit depthbuffer functions.
144 */
145 #define WRITE_DEPTH( _x, _y, d ) \
146 *(GLushort *)(buf + _x*2 + _y*smesa->depthPitch) = d;
147
148 #define READ_DEPTH( d, _x, _y ) \
149 d = *(GLushort *)(buf + _x*2 + _y*smesa->depthPitch);
150
151 #define TAG(x) sis##x##_16
152 #include "depthtmp.h"
153
154
155 /* 32 bit depthbuffer functions.
156 */
157 #define WRITE_DEPTH( _x, _y, d ) \
158 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = d;
159
160 #define READ_DEPTH( d, _x, _y ) \
161 d = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch);
162
163 #define TAG(x) sis##x##_32
164 #include "depthtmp.h"
165
166
167 /* 8/24 bit interleaved depth/stencil functions
168 */
169 #define WRITE_DEPTH( _x, _y, d ) { \
170 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch); \
171 tmp &= 0xff000000; \
172 tmp |= (d & 0x00ffffff); \
173 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = tmp; \
174 }
175
176 #define READ_DEPTH( d, _x, _y ) { \
177 d = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) & 0x00ffffff; \
178 }
179
180 #define TAG(x) sis##x##_24_8
181 #include "depthtmp.h"
182
183 #define WRITE_STENCIL( _x, _y, d ) { \
184 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch); \
185 tmp &= 0x00ffffff; \
186 tmp |= (d << 24); \
187 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = tmp; \
188 }
189
190 #define READ_STENCIL( d, _x, _y ) \
191 d = (*(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) & 0xff000000) >> 24;
192
193 #define TAG(x) sis##x##_24_8
194 #include "stenciltmp.h"
195
196 /*
197 * This function is called to specify which buffer to read and write
198 * for software rasterization (swrast) fallbacks. This doesn't necessarily
199 * correspond to glDrawBuffer() or glReadBuffer() calls.
200 */
201 static void sisDDSetBuffer( GLcontext *ctx,
202 GLframebuffer *colorBuffer,
203 GLuint bufferBit )
204 {
205 sisContextPtr smesa = SIS_CONTEXT(ctx);
206
207 switch ( bufferBit ) {
208 case DD_FRONT_LEFT_BIT:
209 smesa->drawOffset = smesa->readOffset = smesa->frontOffset;
210 smesa->drawPitch = smesa->readPitch = smesa->frontPitch;
211 break;
212 case DD_BACK_LEFT_BIT:
213 smesa->drawOffset = smesa->readOffset = smesa->backOffset;
214 smesa->drawPitch = smesa->readPitch = smesa->backPitch;
215 break;
216 default:
217 break;
218 }
219 }
220
221 void sisSpanRenderStart( GLcontext *ctx )
222 {
223 sisContextPtr smesa = SIS_CONTEXT(ctx);
224
225 SIS_FIREVERTICES(smesa);
226 LOCK_HARDWARE();
227 WaitEngIdle( smesa );
228 }
229
230 void sisSpanRenderFinish( GLcontext *ctx )
231 {
232 sisContextPtr smesa = SIS_CONTEXT(ctx);
233
234 _swrast_flush( ctx );
235 UNLOCK_HARDWARE();
236 }
237
238 void
239 sisDDInitSpanFuncs( GLcontext *ctx )
240 {
241 sisContextPtr smesa = SIS_CONTEXT(ctx);
242 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
243
244 swdd->SetBuffer = sisDDSetBuffer;
245
246 switch (smesa->zFormat)
247 {
248 case SiS_ZFORMAT_Z16:
249 swdd->ReadDepthSpan = sisReadDepthSpan_16;
250 swdd->ReadDepthPixels = sisReadDepthPixels_16;
251 swdd->WriteDepthSpan = sisWriteDepthSpan_16;
252 swdd->WriteDepthPixels = sisWriteDepthPixels_16;
253
254 swdd->ReadStencilSpan = NULL;
255 swdd->ReadStencilPixels = NULL;
256 swdd->WriteStencilSpan = NULL;
257 swdd->WriteStencilPixels = NULL;
258 break;
259 case SiS_ZFORMAT_Z32:
260 swdd->ReadDepthSpan = sisReadDepthSpan_32;
261 swdd->ReadDepthPixels = sisReadDepthPixels_32;
262 swdd->WriteDepthSpan = sisWriteDepthSpan_32;
263 swdd->WriteDepthPixels = sisWriteDepthPixels_32;
264
265 swdd->ReadStencilSpan = NULL;
266 swdd->ReadStencilPixels = NULL;
267 swdd->WriteStencilSpan = NULL;
268 swdd->WriteStencilPixels = NULL;
269 break;
270 case SiS_ZFORMAT_S8Z24:
271 swdd->ReadDepthSpan = sisReadDepthSpan_24_8;
272 swdd->ReadDepthPixels = sisReadDepthPixels_24_8;
273 swdd->WriteDepthSpan = sisWriteDepthSpan_24_8;
274 swdd->WriteDepthPixels = sisWriteDepthPixels_24_8;
275
276 swdd->ReadStencilSpan = sisReadStencilSpan_24_8;
277 swdd->ReadStencilPixels = sisReadStencilPixels_24_8;
278 swdd->WriteStencilSpan = sisWriteStencilSpan_24_8;
279 swdd->WriteStencilPixels = sisWriteStencilPixels_24_8;
280 break;
281 }
282
283 switch ( smesa->bytesPerPixel )
284 {
285 case 2:
286 swdd->WriteRGBASpan = sisWriteRGBASpan_565;
287 swdd->WriteRGBSpan = sisWriteRGBSpan_565;
288 swdd->WriteMonoRGBASpan = sisWriteMonoRGBASpan_565;
289 swdd->WriteRGBAPixels = sisWriteRGBAPixels_565;
290 swdd->WriteMonoRGBAPixels = sisWriteMonoRGBAPixels_565;
291 swdd->ReadRGBASpan = sisReadRGBASpan_565;
292 swdd->ReadRGBAPixels = sisReadRGBAPixels_565;
293 break;
294 case 4:
295 swdd->WriteRGBASpan = sisWriteRGBASpan_8888;
296 swdd->WriteRGBSpan = sisWriteRGBSpan_8888;
297 swdd->WriteMonoRGBASpan = sisWriteMonoRGBASpan_8888;
298 swdd->WriteRGBAPixels = sisWriteRGBAPixels_8888;
299 swdd->WriteMonoRGBAPixels = sisWriteMonoRGBAPixels_8888;
300 swdd->ReadRGBASpan = sisReadRGBASpan_8888;
301 swdd->ReadRGBAPixels = sisReadRGBAPixels_8888;
302 break;
303 default:
304 sis_fatal_error("Bad bytesPerPixel.\n");
305 break;
306 }
307
308 swdd->WriteCI8Span = NULL;
309 swdd->WriteCI32Span = NULL;
310 swdd->WriteMonoCISpan = NULL;
311 swdd->WriteCI32Pixels = NULL;
312 swdd->WriteMonoCIPixels = NULL;
313 swdd->ReadCI32Span = NULL;
314 swdd->ReadCI32Pixels = NULL;
315
316 swdd->SpanRenderStart = sisSpanRenderStart;
317 swdd->SpanRenderFinish = sisSpanRenderFinish;
318 }