new Makefiles
[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
38 #include "swrast/swrast.h"
39
40 #define DBG 0
41
42 #define LOCAL_VARS \
43 sisContextPtr smesa = SIS_CONTEXT(ctx); \
44 char *buf = (char *)(smesa->FbBase + smesa->drawOffset); \
45 char *read_buf = (char *)(smesa->FbBase + smesa->readOffset); \
46 GLuint p; \
47 (void) read_buf; (void) buf; (void) p
48
49 #define LOCAL_DEPTH_VARS \
50 sisContextPtr smesa = SIS_CONTEXT(ctx); \
51 char *buf = smesa->depthbuffer; \
52
53 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
54
55 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
56 _y >= miny && _y < maxy)
57
58 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
59 if ( _y < miny || _y >= maxy ) { \
60 _n1 = 0, _x1 = x; \
61 } else { \
62 _n1 = _n; \
63 _x1 = _x; \
64 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
65 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
66 }
67
68 #define HW_LOCK() do {} while(0);
69
70 #define HW_CLIPLOOP() \
71 do { \
72 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
73 int _nc = dPriv->numClipRects; \
74 \
75 while ( _nc-- ) { \
76 int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \
77 int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \
78 int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \
79 int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
80
81 #define HW_ENDCLIPLOOP() \
82 } \
83 } while (0)
84
85 #define HW_UNLOCK() do {} while(0);
86
87 /* RGB565 */
88 #define INIT_MONO_PIXEL(p, color) \
89 p = SISPACKCOLOR565( color[0], color[1], color[2] )
90
91 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
92 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = \
93 (((r & 0xf8) << 8) | \
94 ((g & 0xfc) << 3) | \
95 (b >> 3))
96
97 #define WRITE_PIXEL( _x, _y, p ) \
98 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = p
99
100 #define READ_RGBA( rgba, _x, _y ) \
101 do { \
102 GLushort p = *(GLushort *)(read_buf + _x*2 + _y*smesa->readPitch); \
103 rgba[0] = (p & 0xf800) >> 8; \
104 rgba[1] = (p & 0x07e0) >> 3; \
105 rgba[2] = (p & 0x001f) << 3; \
106 rgba[3] = 0xff; \
107 } while(0)
108
109 #define TAG(x) sis##x##_565
110 #include "spantmp.h"
111
112
113 /* ARGB8888 */
114 #undef INIT_MONO_PIXEL
115 #define INIT_MONO_PIXEL(p, color) \
116 p = SISPACKCOLOR8888( color[0], color[1], color[2], color[3] )
117
118 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
119 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = \
120 (((a) << 24) | \
121 ((r) << 16) | \
122 ((g) << 8) | \
123 ((b)))
124
125 #define WRITE_PIXEL( _x, _y, p ) \
126 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = p
127
128 #define READ_RGBA( rgba, _x, _y ) \
129 do { \
130 GLuint p = *(GLuint *)(read_buf + _x*4 + _y*smesa->readPitch); \
131 rgba[0] = (p >> 16) & 0xff; \
132 rgba[1] = (p >> 8) & 0xff; \
133 rgba[2] = (p >> 0) & 0xff; \
134 rgba[3] = 0xff; \
135 } while(0)
136
137 #define TAG(x) sis##x##_8888
138 #include "spantmp.h"
139
140
141 /* 16 bit depthbuffer functions.
142 */
143 #define WRITE_DEPTH( _x, _y, d ) \
144 *(GLushort *)(buf + _x*2 + _y*smesa->depthPitch) = d;
145
146 #define READ_DEPTH( d, _x, _y ) \
147 d = *(GLushort *)(buf + _x*2 + _y*smesa->depthPitch);
148
149 #define TAG(x) sis##x##_16
150 #include "depthtmp.h"
151
152
153 /* 32 bit depthbuffer functions.
154 */
155 #define WRITE_DEPTH( _x, _y, d ) \
156 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = d;
157
158 #define READ_DEPTH( d, _x, _y ) \
159 d = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch);
160
161 #define TAG(x) sis##x##_32
162 #include "depthtmp.h"
163
164
165 /* 8/24 bit interleaved depth/stencil functions
166 */
167 #define WRITE_DEPTH( _x, _y, d ) { \
168 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch); \
169 tmp &= 0xff000000; \
170 tmp |= (d & 0x00ffffff); \
171 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = tmp; \
172 }
173
174 #define READ_DEPTH( d, _x, _y ) { \
175 d = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) & 0x00ffffff; \
176 }
177
178 #define TAG(x) sis##x##_24_8
179 #include "depthtmp.h"
180
181 #define WRITE_STENCIL( _x, _y, d ) { \
182 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch); \
183 tmp &= 0x00ffffff; \
184 tmp |= (d << 24); \
185 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = tmp; \
186 }
187
188 #define READ_STENCIL( d, _x, _y ) \
189 d = (*(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) & 0xff000000) >> 24;
190
191 #define TAG(x) sis##x##_24_8
192 #include "stenciltmp.h"
193
194 /*
195 * This function is called to specify which buffer to read and write
196 * for software rasterization (swrast) fallbacks. This doesn't necessarily
197 * correspond to glDrawBuffer() or glReadBuffer() calls.
198 */
199 static void sisDDSetBuffer( GLcontext *ctx,
200 GLframebuffer *colorBuffer,
201 GLuint bufferBit )
202 {
203 sisContextPtr smesa = SIS_CONTEXT(ctx);
204
205 switch ( bufferBit ) {
206 case FRONT_LEFT_BIT:
207 smesa->drawOffset = smesa->readOffset = smesa->frontOffset;
208 smesa->drawPitch = smesa->readPitch = smesa->frontPitch;
209 break;
210 case BACK_LEFT_BIT:
211 smesa->drawOffset = smesa->readOffset = smesa->backOffset;
212 smesa->drawPitch = smesa->readPitch = smesa->backPitch;
213 break;
214 default:
215 break;
216 }
217 }
218
219 static void sisSpanRenderStart( GLcontext *ctx )
220 {
221 sisContextPtr smesa = SIS_CONTEXT(ctx);
222
223 WaitEngIdle( smesa );
224 }
225
226 static void sisSpanRenderFinish( GLcontext *ctx )
227 {
228 _swrast_flush( ctx );
229 }
230
231 void
232 sisDDInitSpanFuncs( GLcontext *ctx )
233 {
234 sisContextPtr smesa = SIS_CONTEXT(ctx);
235 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
236
237 swdd->SetBuffer = sisDDSetBuffer;
238
239 switch (smesa->zFormat)
240 {
241 case SiS_ZFORMAT_Z16:
242 swdd->ReadDepthSpan = sisReadDepthSpan_16;
243 swdd->ReadDepthPixels = sisReadDepthPixels_16;
244 swdd->WriteDepthSpan = sisWriteDepthSpan_16;
245 swdd->WriteDepthPixels = sisWriteDepthPixels_16;
246
247 swdd->ReadStencilSpan = NULL;
248 swdd->ReadStencilPixels = NULL;
249 swdd->WriteStencilSpan = NULL;
250 swdd->WriteStencilPixels = NULL;
251 break;
252 case SiS_ZFORMAT_Z32:
253 swdd->ReadDepthSpan = sisReadDepthSpan_32;
254 swdd->ReadDepthPixels = sisReadDepthPixels_32;
255 swdd->WriteDepthSpan = sisWriteDepthSpan_32;
256 swdd->WriteDepthPixels = sisWriteDepthPixels_32;
257
258 swdd->ReadStencilSpan = NULL;
259 swdd->ReadStencilPixels = NULL;
260 swdd->WriteStencilSpan = NULL;
261 swdd->WriteStencilPixels = NULL;
262 break;
263 case SiS_ZFORMAT_S8Z24:
264 swdd->ReadDepthSpan = sisReadDepthSpan_24_8;
265 swdd->ReadDepthPixels = sisReadDepthPixels_24_8;
266 swdd->WriteDepthSpan = sisWriteDepthSpan_24_8;
267 swdd->WriteDepthPixels = sisWriteDepthPixels_24_8;
268
269 swdd->ReadStencilSpan = sisReadStencilSpan_24_8;
270 swdd->ReadStencilPixels = sisReadStencilPixels_24_8;
271 swdd->WriteStencilSpan = sisWriteStencilSpan_24_8;
272 swdd->WriteStencilPixels = sisWriteStencilPixels_24_8;
273 break;
274 }
275
276 switch ( smesa->bytesPerPixel )
277 {
278 case 2:
279 swdd->WriteRGBASpan = sisWriteRGBASpan_565;
280 swdd->WriteRGBSpan = sisWriteRGBSpan_565;
281 swdd->WriteMonoRGBASpan = sisWriteMonoRGBASpan_565;
282 swdd->WriteRGBAPixels = sisWriteRGBAPixels_565;
283 swdd->WriteMonoRGBAPixels = sisWriteMonoRGBAPixels_565;
284 swdd->ReadRGBASpan = sisReadRGBASpan_565;
285 swdd->ReadRGBAPixels = sisReadRGBAPixels_565;
286 break;
287 case 4:
288 swdd->WriteRGBASpan = sisWriteRGBASpan_8888;
289 swdd->WriteRGBSpan = sisWriteRGBSpan_8888;
290 swdd->WriteMonoRGBASpan = sisWriteMonoRGBASpan_8888;
291 swdd->WriteRGBAPixels = sisWriteRGBAPixels_8888;
292 swdd->WriteMonoRGBAPixels = sisWriteMonoRGBAPixels_8888;
293 swdd->ReadRGBASpan = sisReadRGBASpan_8888;
294 swdd->ReadRGBAPixels = sisReadRGBAPixels_8888;
295 break;
296 default:
297 assert(0);
298 break;
299 }
300
301 swdd->WriteCI8Span = NULL;
302 swdd->WriteCI32Span = NULL;
303 swdd->WriteMonoCISpan = NULL;
304 swdd->WriteCI32Pixels = NULL;
305 swdd->WriteMonoCIPixels = NULL;
306 swdd->ReadCI32Span = NULL;
307 swdd->ReadCI32Pixels = NULL;
308
309 swdd->SpanRenderStart = sisSpanRenderStart;
310 swdd->SpanRenderFinish = sisSpanRenderFinish;
311 }