1 /**************************************************************************
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
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:
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
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.
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_span.c,v 1.5 2001/03/21 16:14:26 dawes Exp $ */
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
35 #include "sis_context.h"
40 #include "swrast/swrast.h"
45 sisContextPtr smesa = SIS_CONTEXT(ctx); \
46 char *buf = (char *)(smesa->FbBase + smesa->drawOffset); \
47 char *read_buf = (char *)(smesa->FbBase + smesa->readOffset); \
49 (void) read_buf; (void) buf; (void) p
51 #define LOCAL_DEPTH_VARS \
52 sisContextPtr smesa = SIS_CONTEXT(ctx); \
53 char *buf = smesa->depthbuffer; \
55 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
57 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
58 _y >= miny && _y < maxy)
60 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
61 if ( _y < miny || _y >= maxy ) { \
66 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
67 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
70 #define HW_LOCK() do {} while(0);
72 #define HW_CLIPLOOP() \
74 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
75 int _nc = dPriv->numClipRects; \
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;
83 #define HW_ENDCLIPLOOP() \
87 #define HW_UNLOCK() do {} while(0);
90 #define INIT_MONO_PIXEL(p, color) \
91 p = SISPACKCOLOR565( color[0], color[1], color[2] )
93 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
94 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = \
95 (((r & 0xf8) << 8) | \
99 #define WRITE_PIXEL( _x, _y, p ) \
100 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = p
102 #define READ_RGBA( rgba, _x, _y ) \
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; \
111 #define TAG(x) sis##x##_565
116 #undef INIT_MONO_PIXEL
117 #define INIT_MONO_PIXEL(p, color) \
118 p = SISPACKCOLOR8888( color[0], color[1], color[2], color[3] )
120 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
121 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = \
127 #define WRITE_PIXEL( _x, _y, p ) \
128 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = p
130 #define READ_RGBA( rgba, _x, _y ) \
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; \
139 #define TAG(x) sis##x##_8888
143 /* 16 bit depthbuffer functions.
145 #define WRITE_DEPTH( _x, _y, d ) \
146 *(GLushort *)(buf + (_x)*2 + (_y)*smesa->depthPitch) = d;
148 #define READ_DEPTH( d, _x, _y ) \
149 d = *(GLushort *)(buf + (_x)*2 + (_y)*smesa->depthPitch);
151 #define TAG(x) sis##x##_16
152 #include "depthtmp.h"
155 /* 32 bit depthbuffer functions.
157 #define WRITE_DEPTH( _x, _y, d ) \
158 *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch) = d;
160 #define READ_DEPTH( d, _x, _y ) \
161 d = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch);
163 #define TAG(x) sis##x##_32
164 #include "depthtmp.h"
167 /* 8/24 bit interleaved depth/stencil functions
169 #define WRITE_DEPTH( _x, _y, d ) { \
170 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch); \
172 tmp |= (d & 0x00ffffff); \
173 *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch) = tmp; \
176 #define READ_DEPTH( d, _x, _y ) { \
177 d = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch) & 0x00ffffff; \
180 #define TAG(x) sis##x##_24_8
181 #include "depthtmp.h"
183 #define WRITE_STENCIL( _x, _y, d ) { \
184 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch); \
187 *(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch) = tmp; \
190 #define READ_STENCIL( d, _x, _y ) \
191 d = (*(GLuint *)(buf + (_x)*4 + (_y)*smesa->depthPitch) & 0xff000000) >> 24;
193 #define TAG(x) sis##x##_24_8
194 #include "stenciltmp.h"
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.
201 static void sisDDSetBuffer( GLcontext
*ctx
,
202 GLframebuffer
*colorBuffer
,
205 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
207 switch ( bufferBit
) {
208 case DD_FRONT_LEFT_BIT
:
209 smesa
->drawOffset
= smesa
->readOffset
= smesa
->frontOffset
;
210 smesa
->drawPitch
= smesa
->readPitch
= smesa
->frontPitch
;
212 case DD_BACK_LEFT_BIT
:
213 smesa
->drawOffset
= smesa
->readOffset
= smesa
->backOffset
;
214 smesa
->drawPitch
= smesa
->readPitch
= smesa
->backPitch
;
221 void sisSpanRenderStart( GLcontext
*ctx
)
223 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
225 SIS_FIREVERTICES(smesa
);
227 WaitEngIdle( smesa
);
230 void sisSpanRenderFinish( GLcontext
*ctx
)
232 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
234 _swrast_flush( ctx
);
239 sisDDInitSpanFuncs( GLcontext
*ctx
)
241 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
242 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
244 swdd
->SetBuffer
= sisDDSetBuffer
;
246 switch (smesa
->zFormat
)
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
;
254 swdd
->ReadStencilSpan
= NULL
;
255 swdd
->ReadStencilPixels
= NULL
;
256 swdd
->WriteStencilSpan
= NULL
;
257 swdd
->WriteStencilPixels
= NULL
;
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
;
265 swdd
->ReadStencilSpan
= NULL
;
266 swdd
->ReadStencilPixels
= NULL
;
267 swdd
->WriteStencilSpan
= NULL
;
268 swdd
->WriteStencilPixels
= NULL
;
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
;
276 swdd
->ReadStencilSpan
= sisReadStencilSpan_24_8
;
277 swdd
->ReadStencilPixels
= sisReadStencilPixels_24_8
;
278 swdd
->WriteStencilSpan
= sisWriteStencilSpan_24_8
;
279 swdd
->WriteStencilPixels
= sisWriteStencilPixels_24_8
;
283 switch ( smesa
->bytesPerPixel
)
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
;
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
;
304 sis_fatal_error("Bad bytesPerPixel.\n");
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
;
316 swdd
->SpanRenderStart
= sisSpanRenderStart
;
317 swdd
->SpanRenderFinish
= sisSpanRenderFinish
;