Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / unichrome / via_span.c
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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.
23 */
24
25 #include "main/glheader.h"
26 #include "main/macros.h"
27 #include "main/mtypes.h"
28 #include "main/colormac.h"
29 #include "via_context.h"
30 #include "via_span.h"
31 #include "via_ioctl.h"
32 #include "swrast/swrast.h"
33
34 #define DBG 0
35
36 #define Y_FLIP(_y) (height - _y - 1)
37
38 #define HW_LOCK()
39
40 #define HW_UNLOCK()
41
42 #undef LOCAL_VARS
43 #define LOCAL_VARS \
44 struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb; \
45 __DRIdrawablePrivate *dPriv = vrb->dPriv; \
46 GLuint pitch = vrb->pitch; \
47 GLuint height = dPriv->h; \
48 GLint p = 0; \
49 char *buf = (char *)(vrb->origMap); \
50 (void) p;
51
52 /* ================================================================
53 * Color buffer
54 */
55
56 /* 16 bit, RGB565 color spanline and pixel functions
57 */
58 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
59 #define SPANTMP_PIXEL_FMT GL_RGB
60 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
61
62 #define TAG(x) via##x##_565
63 #define TAG2(x,y) via##x##_565##y
64 #include "spantmp2.h"
65
66
67 /* 32 bit, ARGB8888 color spanline and pixel functions
68 */
69 #define GET_PTR(_x, _y) (buf + (_x) * 4 + (_y) * pitch)
70 #define SPANTMP_PIXEL_FMT GL_BGRA
71 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
72
73 #define TAG(x) via##x##_8888
74 #define TAG2(x,y) via##x##_8888##y
75 #include "spantmp2.h"
76
77
78 /* 16 bit depthbuffer functions.
79 */
80 #define LOCAL_DEPTH_VARS \
81 struct via_renderbuffer *vrb = (struct via_renderbuffer *) rb; \
82 __DRIdrawablePrivate *dPriv = vrb->dPriv; \
83 GLuint depth_pitch = vrb->pitch; \
84 GLuint height = dPriv->h; \
85 char *buf = (char *)(vrb->map)
86
87 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
88
89 #define VALUE_TYPE GLushort
90
91 #define WRITE_DEPTH(_x, _y, d) \
92 *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
93
94 #define READ_DEPTH(d, _x, _y) \
95 d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
96
97 #define TAG(x) via##x##_z16
98 #include "depthtmp.h"
99
100 /* 32 bit depthbuffer functions.
101 */
102 #define VALUE_TYPE GLuint
103
104 #define WRITE_DEPTH(_x, _y, d) \
105 *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
106
107 #define READ_DEPTH(d, _x, _y) \
108 d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
109
110 #define TAG(x) via##x##_z32
111 #include "depthtmp.h"
112
113
114
115 /* 24/8 bit interleaved depth/stencil functions
116 */
117 #define VALUE_TYPE GLuint
118
119 #define WRITE_DEPTH( _x, _y, d ) { \
120 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
121 tmp &= 0x000000ff; \
122 tmp |= ((d)<<8); \
123 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
124 }
125
126 #define READ_DEPTH( d, _x, _y ) \
127 d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
128
129
130 #define TAG(x) via##x##_z24_s8
131 #include "depthtmp.h"
132
133 #define WRITE_STENCIL( _x, _y, d ) { \
134 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
135 tmp &= 0xffffff00; \
136 tmp |= (d); \
137 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
138 }
139
140 #define READ_STENCIL( d, _x, _y ) \
141 d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
142
143 #define TAG(x) via##x##_z24_s8
144 #include "stenciltmp.h"
145
146
147
148
149 /* Move locking out to get reasonable span performance.
150 */
151 void viaSpanRenderStart( GLcontext *ctx )
152 {
153 struct via_context *vmesa = VIA_CONTEXT(ctx);
154 viaWaitIdle(vmesa, GL_FALSE);
155 LOCK_HARDWARE(vmesa);
156 }
157
158 void viaSpanRenderFinish( GLcontext *ctx )
159 {
160 struct via_context *vmesa = VIA_CONTEXT(ctx);
161 _swrast_flush( ctx );
162 UNLOCK_HARDWARE( vmesa );
163 }
164
165 void viaInitSpanFuncs(GLcontext *ctx)
166 {
167 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
168 swdd->SpanRenderStart = viaSpanRenderStart;
169 swdd->SpanRenderFinish = viaSpanRenderFinish;
170 }
171
172
173
174 /**
175 * Plug in the Get/Put routines for the given driRenderbuffer.
176 */
177 void
178 viaSetSpanFunctions(struct via_renderbuffer *vrb, const GLvisual *vis)
179 {
180 if (vrb->Base.InternalFormat == GL_RGBA) {
181 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
182 viaInitPointers_565(&vrb->Base);
183 }
184 else {
185 viaInitPointers_8888(&vrb->Base);
186 }
187 }
188 else if (vrb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
189 viaInitDepthPointers_z16(&vrb->Base);
190 }
191 else if (vrb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
192 viaInitDepthPointers_z24_s8(&vrb->Base);
193 }
194 else if (vrb->Base.InternalFormat == GL_DEPTH_COMPONENT32) {
195 viaInitDepthPointers_z32(&vrb->Base);
196 }
197 else if (vrb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
198 viaInitStencilPointers_z24_s8(&vrb->Base);
199 }
200 }