2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
29 #include "via_context.h"
31 #include "via_ioctl.h"
32 #include "swrast/swrast.h"
36 #define CLIPPIXEL(_x,_y) (_x >= minx && _x < maxx && \
37 _y >= miny && _y < maxy)
40 #define CLIPSPAN(_x, _y, _n, _x1, _n1, _i) \
41 if (_y < miny || _y >= maxy) { \
47 if (_x1 < minx) _i += (minx -_x1), n1 -= (minx -_x1), _x1 = minx; \
48 if (_x1 + _n1 >= maxx) n1 -= (_x1 + n1 - maxx); \
51 #define Y_FLIP(_y) (height - _y - 1)
54 #define HW_CLIPLOOP() \
56 __DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
57 int _nc = dPriv->numClipRects; \
59 int minx = dPriv->pClipRects[_nc].x1 - dPriv->x; \
60 int miny = dPriv->pClipRects[_nc].y1 - dPriv->y; \
61 int maxx = dPriv->pClipRects[_nc].x2 - dPriv->x; \
62 int maxy = dPriv->pClipRects[_nc].y2 - dPriv->y;
65 #define HW_ENDCLIPLOOP() \
73 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
74 __DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
75 GLuint draw_pitch = vmesa->drawBuffer->pitch; \
76 GLuint read_pitch = vmesa->readBuffer->pitch; \
77 GLuint height = dPriv->h; \
79 char *buf = (char *)(vmesa->drawBuffer->origMap + vmesa->drawXoff * vmesa->viaScreen->bytesPerPixel); \
80 char *read_buf = (char *)(vmesa->readBuffer->origMap + vmesa->drawXoff * vmesa->viaScreen->bytesPerPixel); \
81 (void) (read_pitch && draw_pitch && buf && read_buf && p);
83 /* ================================================================
87 /* 16 bit, RGB565 color spanline and pixel functions
89 #define GET_SRC_PTR(_x, _y) (read_buf + _x * 2 + _y * read_pitch)
90 #define GET_DST_PTR(_x, _y) ( buf + _x * 2 + _y * draw_pitch)
91 #define SPANTMP_PIXEL_FMT GL_RGB
92 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
94 #define TAG(x) via##x##_565
95 #define TAG2(x,y) via##x##_565##y
99 /* 32 bit, ARGB8888 color spanline and pixel functions
101 #define GET_SRC_PTR(_x, _y) (read_buf + _x * 4 + _y * read_pitch)
102 #define GET_DST_PTR(_x, _y) ( buf + _x * 4 + _y * draw_pitch)
103 #define SPANTMP_PIXEL_FMT GL_BGRA
104 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
106 #define TAG(x) via##x##_8888
107 #define TAG2(x,y) via##x##_8888##y
108 #include "spantmp2.h"
111 /* 16 bit depthbuffer functions.
113 #define LOCAL_DEPTH_VARS \
114 viaContextPtr vmesa = VIA_CONTEXT(ctx); \
115 __DRIdrawablePrivate *dPriv = vmesa->driDrawable; \
116 GLuint depth_pitch = vmesa->depth.pitch; \
117 GLuint height = dPriv->h; \
118 char *buf = (char *)(vmesa->depth.map + (vmesa->drawXoff * vmesa->depth.bpp/8))
120 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
123 #define WRITE_DEPTH(_x, _y, d) \
124 *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
126 #define READ_DEPTH(d, _x, _y) \
127 d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
129 #define TAG(x) via##x##_16
130 #include "depthtmp.h"
132 /* 32 bit depthbuffer functions.
134 #define WRITE_DEPTH(_x, _y, d) \
135 *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
137 #define READ_DEPTH(d, _x, _y) \
138 d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
140 #define TAG(x) via##x##_32
141 #include "depthtmp.h"
145 /* 24/8 bit interleaved depth/stencil functions
147 #define WRITE_DEPTH( _x, _y, d ) { \
148 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
151 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
154 #define READ_DEPTH( d, _x, _y ) \
155 d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
158 #define TAG(x) via##x##_24_8
159 #include "depthtmp.h"
161 #define WRITE_STENCIL( _x, _y, d ) { \
162 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
165 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
168 #define READ_STENCIL( d, _x, _y ) \
169 d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
171 #define TAG(x) via##x##_24_8
172 #include "stenciltmp.h"
176 static void viaSetBuffer(GLcontext
*ctx
, GLframebuffer
*colorBuffer
,
179 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
181 if (bufferBit
== DD_FRONT_LEFT_BIT
) {
182 vmesa
->drawBuffer
= vmesa
->readBuffer
= &vmesa
->front
;
184 else if (bufferBit
== DD_BACK_LEFT_BIT
) {
185 vmesa
->drawBuffer
= vmesa
->readBuffer
= &vmesa
->back
;
192 /* Move locking out to get reasonable span performance.
194 void viaSpanRenderStart( GLcontext
*ctx
)
196 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
197 VIA_FINISH_PRIM(vmesa
);
198 LOCK_HARDWARE(vmesa
);
199 viaFlushDmaLocked(vmesa
, 0);
203 void viaSpanRenderFinish( GLcontext
*ctx
)
205 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
206 _swrast_flush( ctx
);
207 UNLOCK_HARDWARE( vmesa
);
210 void viaInitSpanFuncs(GLcontext
*ctx
)
212 viaContextPtr vmesa
= VIA_CONTEXT(ctx
);
213 struct swrast_device_driver
*swdd
= _swrast_GetDeviceDriverReference(ctx
);
215 swdd
->SetBuffer
= viaSetBuffer
;
216 if (vmesa
->viaScreen
->bitsPerPixel
== 16) {
217 viaInitPointers_565( swdd
);
219 else if (vmesa
->viaScreen
->bitsPerPixel
== 32) {
220 viaInitPointers_8888( swdd
);
226 if (vmesa
->glCtx
->Visual
.depthBits
== 16) {
227 swdd
->ReadDepthSpan
= viaReadDepthSpan_16
;
228 swdd
->WriteDepthSpan
= viaWriteDepthSpan_16
;
229 swdd
->WriteMonoDepthSpan
= viaWriteMonoDepthSpan_16
;
230 swdd
->ReadDepthPixels
= viaReadDepthPixels_16
;
231 swdd
->WriteDepthPixels
= viaWriteDepthPixels_16
;
233 else if (vmesa
->glCtx
->Visual
.depthBits
== 24) {
234 swdd
->ReadDepthSpan
= viaReadDepthSpan_24_8
;
235 swdd
->WriteDepthSpan
= viaWriteDepthSpan_24_8
;
236 swdd
->WriteMonoDepthSpan
= viaWriteMonoDepthSpan_24_8
;
237 swdd
->ReadDepthPixels
= viaReadDepthPixels_24_8
;
238 swdd
->WriteDepthPixels
= viaWriteDepthPixels_24_8
;
240 swdd
->WriteStencilSpan
= viaWriteStencilSpan_24_8
;
241 swdd
->ReadStencilSpan
= viaReadStencilSpan_24_8
;
242 swdd
->WriteStencilPixels
= viaWriteStencilPixels_24_8
;
243 swdd
->ReadStencilPixels
= viaReadStencilPixels_24_8
;
245 else if (vmesa
->glCtx
->Visual
.depthBits
== 32) {
246 swdd
->ReadDepthSpan
= viaReadDepthSpan_32
;
247 swdd
->WriteDepthSpan
= viaWriteDepthSpan_32
;
248 swdd
->WriteMonoDepthSpan
= viaWriteMonoDepthSpan_32
;
249 swdd
->ReadDepthPixels
= viaReadDepthPixels_32
;
250 swdd
->WriteDepthPixels
= viaWriteDepthPixels_32
;
253 swdd
->SpanRenderStart
= viaSpanRenderStart
;
254 swdd
->SpanRenderFinish
= viaSpanRenderFinish
;
257 swdd
->WriteCI8Span
= NULL
;
258 swdd
->WriteCI32Span
= NULL
;
259 swdd
->WriteMonoCISpan
= NULL
;
260 swdd
->WriteCI32Pixels
= NULL
;
261 swdd
->WriteMonoCIPixels
= NULL
;
262 swdd
->ReadCI32Span
= NULL
;
263 swdd
->ReadCI32Pixels
= NULL
;