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.
25 #include "main/glheader.h"
26 #include "main/formats.h"
27 #include "main/macros.h"
28 #include "main/mtypes.h"
29 #include "main/colormac.h"
30 #include "via_context.h"
32 #include "via_ioctl.h"
33 #include "swrast/swrast.h"
37 #define Y_FLIP(_y) (height - _y - 1)
45 struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb; \
46 __DRIdrawable *dPriv = vrb->dPriv; \
47 GLuint pitch = vrb->pitch; \
48 GLuint height = dPriv->h; \
50 char *buf = (char *)(vrb->origMap); \
53 /* ================================================================
57 /* 16 bit, RGB565 color spanline and pixel functions
59 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
60 #define SPANTMP_PIXEL_FMT GL_RGB
61 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
63 #define TAG(x) via##x##_565
64 #define TAG2(x,y) via##x##_565##y
68 /* 32 bit, ARGB8888 color spanline and pixel functions
70 #define GET_PTR(_x, _y) (buf + (_x) * 4 + (_y) * pitch)
71 #define SPANTMP_PIXEL_FMT GL_BGRA
72 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
74 #define TAG(x) via##x##_8888
75 #define TAG2(x,y) via##x##_8888##y
79 /* 16 bit depthbuffer functions.
81 #define LOCAL_DEPTH_VARS \
82 struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb; \
83 __DRIdrawable *dPriv = vrb->dPriv; \
84 GLuint depth_pitch = vrb->pitch; \
85 GLuint height = dPriv->h; \
86 char *buf = (char *)(vrb->map)
88 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
90 #define VALUE_TYPE GLushort
92 #define WRITE_DEPTH(_x, _y, d) \
93 *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
95 #define READ_DEPTH(d, _x, _y) \
96 d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
98 #define TAG(x) via##x##_z16
101 /* 32 bit depthbuffer functions.
103 #define VALUE_TYPE GLuint
105 #define WRITE_DEPTH(_x, _y, d) \
106 *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
108 #define READ_DEPTH(d, _x, _y) \
109 d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
111 #define TAG(x) via##x##_z32
112 #include "depthtmp.h"
116 /* 24/8 bit interleaved depth/stencil functions
118 #define VALUE_TYPE GLuint
120 #define WRITE_DEPTH( _x, _y, d ) { \
121 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
124 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
127 #define READ_DEPTH( d, _x, _y ) \
128 d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
131 #define TAG(x) via##x##_z24_s8
132 #include "depthtmp.h"
134 #define WRITE_STENCIL( _x, _y, d ) { \
135 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
138 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
141 #define READ_STENCIL( d, _x, _y ) \
142 d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
144 #define TAG(x) via##x##_z24_s8
145 #include "stenciltmp.h"
150 /* Move locking out to get reasonable span performance.
152 void viaSpanRenderStart( struct gl_context *ctx )
154 struct via_context *vmesa = VIA_CONTEXT(ctx);
155 viaWaitIdle(vmesa, GL_FALSE);
156 LOCK_HARDWARE(vmesa);
159 void viaSpanRenderFinish( struct gl_context *ctx )
161 struct via_context *vmesa = VIA_CONTEXT(ctx);
162 _swrast_flush( ctx );
163 UNLOCK_HARDWARE( vmesa );
166 void viaInitSpanFuncs(struct gl_context *ctx)
168 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
169 swdd->SpanRenderStart = viaSpanRenderStart;
170 swdd->SpanRenderFinish = viaSpanRenderFinish;
176 * Plug in the Get/Put routines for the given driRenderbuffer.
179 viaSetSpanFunctions(struct via_renderbuffer *vrb, const struct gl_config *vis)
181 if (vrb->Base.Format == MESA_FORMAT_RGB565) {
182 viaInitPointers_565(&vrb->Base);
184 else if (vrb->Base.Format == MESA_FORMAT_ARGB8888) {
185 viaInitPointers_8888(&vrb->Base);
187 else if (vrb->Base.Format == MESA_FORMAT_Z16) {
188 viaInitDepthPointers_z16(&vrb->Base);
190 else if (vrb->Base.Format == MESA_FORMAT_Z24_S8) {
191 viaInitDepthPointers_z24_s8(&vrb->Base);
193 else if (vrb->Base.Format == MESA_FORMAT_Z32) {
194 viaInitDepthPointers_z32(&vrb->Base);
196 else if (vrb->Base.Format == MESA_FORMAT_S8) {
197 viaInitStencilPointers_z24_s8(&vrb->Base);