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"
38 #include "swrast/swrast.h"
43 sisContextPtr smesa = SIS_CONTEXT(ctx); \
44 char *buf = (char *)(smesa->FbBase + smesa->drawOffset); \
45 char *read_buf = (char *)(smesa->FbBase + smesa->readOffset); \
47 (void) read_buf; (void) buf; (void) p
49 #define LOCAL_DEPTH_VARS \
50 sisContextPtr smesa = SIS_CONTEXT(ctx); \
51 char *buf = smesa->depthbuffer; \
53 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
55 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
56 _y >= miny && _y < maxy)
58 #define CLIPSPAN( _x, _y, _n, _x1, _n1, _i ) \
59 if ( _y < miny || _y >= maxy ) { \
64 if ( _x1 < minx ) _i += (minx-_x1), n1 -= (minx-_x1), _x1 = minx; \
65 if ( _x1 + _n1 >= maxx ) n1 -= (_x1 + n1 - maxx); \
68 #define HW_LOCK() do {} while(0);
70 #define HW_CLIPLOOP() \
72 __DRIdrawablePrivate *dPriv = smesa->driDrawable; \
73 int _nc = dPriv->numClipRects; \
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;
81 #define HW_ENDCLIPLOOP() \
85 #define HW_UNLOCK() do {} while(0);
88 #define INIT_MONO_PIXEL(p, color) \
89 p = SISPACKCOLOR565( color[0], color[1], color[2] )
91 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
92 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = \
93 (((r & 0xf8) << 8) | \
97 #define WRITE_PIXEL( _x, _y, p ) \
98 *(GLushort *)(buf + _x*2 + _y*smesa->drawPitch) = p
100 #define READ_RGBA( rgba, _x, _y ) \
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; \
109 #define TAG(x) sis##x##_565
114 #undef INIT_MONO_PIXEL
115 #define INIT_MONO_PIXEL(p, color) \
116 p = SISPACKCOLOR8888( color[0], color[1], color[2], color[3] )
118 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
119 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = \
125 #define WRITE_PIXEL( _x, _y, p ) \
126 *(GLuint *)(buf + _x*4 + _y*smesa->drawPitch) = p
128 #define READ_RGBA( rgba, _x, _y ) \
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; \
137 #define TAG(x) sis##x##_8888
141 /* 16 bit depthbuffer functions.
143 #define WRITE_DEPTH( _x, _y, d ) \
144 *(GLushort *)(buf + _x*2 + _y*smesa->depthPitch) = d;
146 #define READ_DEPTH( d, _x, _y ) \
147 d = *(GLushort *)(buf + _x*2 + _y*smesa->depthPitch);
149 #define TAG(x) sis##x##_16
150 #include "depthtmp.h"
153 /* 32 bit depthbuffer functions.
155 #define WRITE_DEPTH( _x, _y, d ) \
156 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = d;
158 #define READ_DEPTH( d, _x, _y ) \
159 d = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch);
161 #define TAG(x) sis##x##_32
162 #include "depthtmp.h"
165 /* 8/24 bit interleaved depth/stencil functions
167 #define WRITE_DEPTH( _x, _y, d ) { \
168 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch); \
170 tmp |= (d & 0x00ffffff); \
171 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = tmp; \
174 #define READ_DEPTH( d, _x, _y ) { \
175 d = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) & 0x00ffffff; \
178 #define TAG(x) sis##x##_24_8
179 #include "depthtmp.h"
181 #define WRITE_STENCIL( _x, _y, d ) { \
182 GLuint tmp = *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch); \
185 *(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) = tmp; \
188 #define READ_STENCIL( d, _x, _y ) \
189 d = (*(GLuint *)(buf + _x*4 + _y*smesa->depthPitch) & 0xff000000) >> 24;
191 #define TAG(x) sis##x##_24_8
192 #include "stenciltmp.h"
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.
199 static void sisDDSetBuffer( GLcontext
*ctx
,
200 GLframebuffer
*colorBuffer
,
203 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
205 switch ( bufferBit
) {
207 smesa
->drawOffset
= smesa
->readOffset
= smesa
->frontOffset
;
208 smesa
->drawPitch
= smesa
->readPitch
= smesa
->frontPitch
;
211 smesa
->drawOffset
= smesa
->readOffset
= smesa
->backOffset
;
212 smesa
->drawPitch
= smesa
->readPitch
= smesa
->backPitch
;
219 static void sisSpanRenderStart( GLcontext
*ctx
)
221 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
223 WaitEngIdle( smesa
);
226 static void sisSpanRenderFinish( GLcontext
*ctx
)
228 _swrast_flush( ctx
);
232 sisDDInitSpanFuncs( GLcontext
*ctx
)
234 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
235 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
237 swdd
->SetBuffer
= sisDDSetBuffer
;
239 switch (smesa
->zFormat
)
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
;
247 swdd
->ReadStencilSpan
= NULL
;
248 swdd
->ReadStencilPixels
= NULL
;
249 swdd
->WriteStencilSpan
= NULL
;
250 swdd
->WriteStencilPixels
= NULL
;
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
;
258 swdd
->ReadStencilSpan
= NULL
;
259 swdd
->ReadStencilPixels
= NULL
;
260 swdd
->WriteStencilSpan
= NULL
;
261 swdd
->WriteStencilPixels
= NULL
;
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
;
269 swdd
->ReadStencilSpan
= sisReadStencilSpan_24_8
;
270 swdd
->ReadStencilPixels
= sisReadStencilPixels_24_8
;
271 swdd
->WriteStencilSpan
= sisWriteStencilSpan_24_8
;
272 swdd
->WriteStencilPixels
= sisWriteStencilPixels_24_8
;
276 switch ( smesa
->bytesPerPixel
)
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
;
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
;
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
;
309 swdd
->SpanRenderStart
= sisSpanRenderStart
;
310 swdd
->SpanRenderFinish
= sisSpanRenderFinish
;