Merge branch 'gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / svga / svgamesa32.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.0
5 * Copyright (C) 1995-2002 Brian Paul
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22
23 /*
24 * SVGA driver for Mesa.
25 * Original author: Brian Paul
26 * Additional authors: Slawomir Szczyrba <steev@hot.pl> (Mesa 3.2)
27 */
28
29 #ifdef HAVE_CONFIG_H
30 #include "conf.h"
31 #endif
32
33 #ifdef SVGA
34
35 #include "svgapix.h"
36 #include "svgamesa32.h"
37 #include "swrast/swrast.h"
38
39
40 #if 0
41 /* this doesn't compile with GCC on RedHat 6.1 */
42 static INLINE int RGB2BGR32(int c)
43 {
44 asm("rorw $8, %0\n"
45 "rorl $16, %0\n"
46 "rorw $8, %0\n"
47 "shrl $8, %0\n"
48 : "=q"(c):"0"(c));
49 return c;
50 }
51 #else
52 static unsigned long RGB2BGR32(unsigned long color)
53 {
54 return (color & 0xff00)|(color>>16)|((color & 0xff)<<16);
55 }
56 #endif
57
58 static void __svga_drawpixel32(int x, int y, unsigned long c)
59 {
60 unsigned long offset;
61
62 GLint *intBuffer=(void *)SVGABuffer.DrawBuffer;
63 y = SVGAInfo->height-y-1;
64 offset = y * SVGAInfo->width + x;
65 intBuffer[offset]=c;
66 }
67
68 static unsigned long __svga_getpixel32(int x, int y)
69 {
70 unsigned long offset;
71
72 const GLint *intBuffer=(void *)SVGABuffer.ReadBuffer;
73 y = SVGAInfo->height-y-1;
74 offset = y * SVGAInfo->width + x;
75 return intBuffer[offset];
76 }
77
78 void __clear_color32( GLcontext *ctx, const GLfloat color[4] )
79 {
80 GLubyte col[3];
81 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
82 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
83 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
84 SVGAMesa->clear_truecolor = (col[0] << 16) | (col[1] << 8) | col[2];
85 }
86
87 void __clear32( GLcontext *ctx, GLbitfield mask )
88 {
89 int i,j;
90 int x = ctx->DrawBuffer->_Xmin;
91 int y = ctx->DrawBuffer->_Ymin;
92 int width = ctx->DrawBuffer->_Xmax - x;
93 int height = ctx->DrawBuffer->_Ymax - y;
94 GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
95
96 if (mask & DD_FRONT_LEFT_BIT) {
97 if (all) {
98 GLint *intBuffer=(void *)SVGABuffer.FrontBuffer;
99 for (i=0;i<SVGABuffer.BufferSize / 4;i++)
100 intBuffer[i]=SVGAMesa->clear_truecolor;
101 }
102 else {
103 GLubyte *tmp = SVGABuffer.DrawBuffer;
104 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
105 for (i=x;i<width;i++)
106 for (j=y;j<height;j++)
107 __svga_drawpixel32(i,j,SVGAMesa->clear_truecolor);
108 SVGABuffer.DrawBuffer = tmp;
109 }
110 mask &= ~DD_FRONT_LEFT_BIT;
111 }
112 if (mask & DD_BACK_LEFT_BIT) {
113 if (all) {
114 GLint *intBuffer=(void *)SVGABuffer.BackBuffer;
115 for (i=0;i<SVGABuffer.BufferSize / 4;i++)
116 intBuffer[i]=SVGAMesa->clear_truecolor;
117 }
118 else {
119 GLubyte *tmp = SVGABuffer.DrawBuffer;
120 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
121 for (i=x;i<width;i++)
122 for (j=y;j<height;j++)
123 __svga_drawpixel32(i,j,SVGAMesa->clear_truecolor);
124 SVGABuffer.DrawBuffer = tmp;
125 }
126 mask &= ~DD_BACK_LEFT_BIT;
127 }
128
129 if (mask)
130 _swrast_Clear( ctx, mask );
131 }
132
133 void __write_rgba_span32( const GLcontext *ctx, GLuint n, GLint x, GLint y,
134 const GLubyte rgba[][4], const GLubyte mask[] )
135 {
136 int i;
137 if (mask) {
138 /* draw some pixels */
139 for (i=0; i<n; i++, x++) {
140 if (mask[i]) {
141 __svga_drawpixel32( x, y, RGB2BGR32(*((GLint*)rgba[i])));
142 }
143 }
144 }
145 else {
146 /* draw all pixels */
147 for (i=0; i<n; i++, x++) {
148 __svga_drawpixel32( x, y, RGB2BGR32(*((GLint*)rgba[i])));
149 }
150 }
151 }
152
153 void __write_mono_rgba_span32( const GLcontext *ctx,
154 GLuint n, GLint x, GLint y,
155 const GLchan color[4], const GLubyte mask[])
156 {
157 int i;
158 GLuint truecolor = color[RCOMP]<<16 | color[GCOMP]<<8 | color[BCOMP];
159 for (i=0; i<n; i++, x++) {
160 if (mask[i]) {
161 __svga_drawpixel32( x, y, truecolor);
162 }
163 }
164 }
165
166 void __read_rgba_span32( const GLcontext *ctx, GLuint n, GLint x, GLint y,
167 GLubyte rgba[][4] )
168 {
169 int i;
170 for (i=0; i<n; i++, x++) {
171 *((GLint*)rgba[i]) = RGB2BGR32(__svga_getpixel32( x, y ));
172 }
173 }
174
175 void __write_rgba_pixels32( const GLcontext *ctx,
176 GLuint n, const GLint x[], const GLint y[],
177 const GLubyte rgba[][4], const GLubyte mask[] )
178 {
179 int i;
180 for (i=0; i<n; i++) {
181 if (mask[i]) {
182 __svga_drawpixel32( x[i], y[i], RGB2BGR32(*((GLint*)rgba[i])));
183 }
184 }
185 }
186
187 void __write_mono_rgba_pixels32( const GLcontext *ctx,
188 GLuint n,
189 const GLint x[], const GLint y[],
190 const GLchan color[4], const GLubyte mask[] )
191 {
192 GLuint truecolor = color[RCOMP]<<16 | color[GCOMP]<<8 | color[BCOMP];
193 int i;
194 for (i=0; i<n; i++) {
195 if (mask[i]) {
196 __svga_drawpixel32( x[i], y[i], truecolor );
197 }
198 }
199 }
200
201 void __read_rgba_pixels32( const GLcontext *ctx,
202 GLuint n, const GLint x[], const GLint y[],
203 GLubyte rgba[][4], const GLubyte mask[] )
204 {
205 int i;
206 for (i=0; i<n; i++,x++) {
207 *((GLint*)rgba[i]) = RGB2BGR32(__svga_getpixel32( x[i], y[i] ));
208 }
209 }
210
211
212 #else
213
214
215 /* silence compiler warning */
216 extern void _mesa_svga32_dummy_function(void);
217 void _mesa_svga32_dummy_function(void)
218 {
219 }
220
221
222 #endif
223