Make utils.h self-contained.
[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 "glheader.h"
26 #include "macros.h"
27 #include "mtypes.h"
28 #include "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
90 #define WRITE_DEPTH(_x, _y, d) \
91 *(GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch) = d;
92
93 #define READ_DEPTH(d, _x, _y) \
94 d = *(volatile GLushort *)(buf + (_x) * 2 + (_y) * depth_pitch);
95
96 #define TAG(x) via##x##_z16
97 #include "depthtmp.h"
98
99 /* 32 bit depthbuffer functions.
100 */
101 #define WRITE_DEPTH(_x, _y, d) \
102 *(GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch) = d;
103
104 #define READ_DEPTH(d, _x, _y) \
105 d = *(volatile GLuint *)(buf + (_x) * 4 + (_y) * depth_pitch);
106
107 #define TAG(x) via##x##_z32
108 #include "depthtmp.h"
109
110
111
112 /* 24/8 bit interleaved depth/stencil functions
113 */
114 #define WRITE_DEPTH( _x, _y, d ) { \
115 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
116 tmp &= 0x000000ff; \
117 tmp |= ((d)<<8); \
118 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
119 }
120
121 #define READ_DEPTH( d, _x, _y ) \
122 d = (*(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch)) >> 8;
123
124
125 #define TAG(x) via##x##_z24_s8
126 #include "depthtmp.h"
127
128 #define WRITE_STENCIL( _x, _y, d ) { \
129 GLuint tmp = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch); \
130 tmp &= 0xffffff00; \
131 tmp |= (d); \
132 *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) = tmp; \
133 }
134
135 #define READ_STENCIL( d, _x, _y ) \
136 d = *(GLuint *)(buf + (_x)*4 + (_y)*depth_pitch) & 0xff;
137
138 #define TAG(x) via##x##_z24_s8
139 #include "stenciltmp.h"
140
141
142
143
144 /* Move locking out to get reasonable span performance.
145 */
146 void viaSpanRenderStart( GLcontext *ctx )
147 {
148 struct via_context *vmesa = VIA_CONTEXT(ctx);
149 viaWaitIdle(vmesa, GL_FALSE);
150 LOCK_HARDWARE(vmesa);
151 }
152
153 void viaSpanRenderFinish( GLcontext *ctx )
154 {
155 struct via_context *vmesa = VIA_CONTEXT(ctx);
156 _swrast_flush( ctx );
157 UNLOCK_HARDWARE( vmesa );
158 }
159
160 void viaInitSpanFuncs(GLcontext *ctx)
161 {
162 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
163 swdd->SpanRenderStart = viaSpanRenderStart;
164 swdd->SpanRenderFinish = viaSpanRenderFinish;
165 }
166
167
168
169 /**
170 * Plug in the Get/Put routines for the given driRenderbuffer.
171 */
172 void
173 viaSetSpanFunctions(struct via_renderbuffer *vrb, const GLvisual *vis)
174 {
175 if (vrb->Base.InternalFormat == GL_RGBA) {
176 if (vis->redBits == 5 && vis->greenBits == 6 && vis->blueBits == 5) {
177 viaInitPointers_565(&vrb->Base);
178 }
179 else {
180 viaInitPointers_8888(&vrb->Base);
181 }
182 }
183 else if (vrb->Base.InternalFormat == GL_DEPTH_COMPONENT16) {
184 viaInitDepthPointers_z16(&vrb->Base);
185 }
186 else if (vrb->Base.InternalFormat == GL_DEPTH_COMPONENT24) {
187 viaInitDepthPointers_z24_s8(&vrb->Base);
188 }
189 else if (vrb->Base.InternalFormat == GL_DEPTH_COMPONENT32) {
190 viaInitDepthPointers_z32(&vrb->Base);
191 }
192 else if (vrb->Base.InternalFormat == GL_STENCIL_INDEX8_EXT) {
193 viaInitStencilPointers_z24_s8(&vrb->Base);
194 }
195 }