Remove CVS keywords.
[mesa.git] / src / mesa / drivers / svga / svgamesa24.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 "svgamesa24.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 RGB2BGR24(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 RGB2BGR24(unsigned long color)
53 {
54 return (color & 0xff00)|(color>>16)|((color & 0xff)<<16);
55 }
56 #endif
57
58 static void __svga_drawpixel24(int x, int y, GLubyte r, GLubyte g, GLubyte b)
59 {
60 unsigned long offset;
61
62 _RGB *rgbBuffer=(void *)SVGABuffer.DrawBuffer;
63 y = SVGAInfo->height-y-1;
64 offset = y * SVGAInfo->width + x;
65
66 rgbBuffer[offset].r=r;
67 rgbBuffer[offset].g=g;
68 rgbBuffer[offset].b=b;
69 }
70
71 static unsigned long __svga_getpixel24(int x, int y)
72 {
73 unsigned long offset;
74
75 _RGB *rgbBuffer=(void *)SVGABuffer.ReadBuffer;
76 y = SVGAInfo->height-y-1;
77 offset = y * SVGAInfo->width + x;
78 return rgbBuffer[offset].r<<16 | rgbBuffer[offset].g<<8 | rgbBuffer[offset].b;
79 }
80
81 void __clear_color24( GLcontext *ctx, const GLfloat color[4] )
82 {
83 GLubyte col[3];
84 CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
85 CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
86 CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
87 SVGAMesa->clear_red = col[0];
88 SVGAMesa->clear_green = col[1];
89 SVGAMesa->clear_blue = col[2];
90 /* SVGAMesa->clear_truecolor = red<<16 | green<<8 | blue; */
91 }
92
93 void __clear24( GLcontext *ctx, GLbitfield mask )
94 {
95 int i,j;
96 int x = ctx->DrawBuffer->_Xmin;
97 int y = ctx->DrawBuffer->_Ymin;
98 int width = ctx->DrawBuffer->_Xmax - x;
99 int height = ctx->DrawBuffer->_Ymax - y;
100 GLboolean all = (width == ctx->DrawBuffer->Width && height == ctx->DrawBuffer->height)
101
102 if (mask & DD_FRONT_LEFT_BIT) {
103 if (all) {
104 _RGB *rgbBuffer=(void *)SVGABuffer.FrontBuffer;
105 for (i=0;i<SVGABuffer.BufferSize / 3;i++) {
106 rgbBuffer[i].r=SVGAMesa->clear_red;
107 rgbBuffer[i].g=SVGAMesa->clear_green;
108 rgbBuffer[i].b=SVGAMesa->clear_blue;
109 }
110 }
111 else {
112 GLubyte *tmp = SVGABuffer.DrawBuffer;
113 SVGABuffer.DrawBuffer = SVGABuffer.FrontBuffer;
114 for (i=x;i<width;i++)
115 for (j=y;j<height;j++)
116 __svga_drawpixel24( i, j, SVGAMesa->clear_red,
117 SVGAMesa->clear_green,
118 SVGAMesa->clear_blue);
119 SVGABuffer.DrawBuffer = tmp;
120 }
121 mask &= ~DD_FRONT_LEFT_BIT;
122 }
123 if (mask & DD_BACK_LEFT_BIT) {
124 if (all) {
125 _RGB *rgbBuffer=(void *)SVGABuffer.BackBuffer;
126 for (i=0;i<SVGABuffer.BufferSize / 3;i++) {
127 rgbBuffer[i].r=SVGAMesa->clear_red;
128 rgbBuffer[i].g=SVGAMesa->clear_green;
129 rgbBuffer[i].b=SVGAMesa->clear_blue;
130 }
131 }
132 else {
133 GLubyte *tmp = SVGABuffer.DrawBuffer;
134 SVGABuffer.DrawBuffer = SVGABuffer.BackBuffer;
135 for (i=x;i<width;i++)
136 for (j=y;j<height;j++)
137 __svga_drawpixel24( i, j, SVGAMesa->clear_red,
138 SVGAMesa->clear_green,
139 SVGAMesa->clear_blue);
140 SVGABuffer.DrawBuffer = tmp;
141 }
142 mask &= ~DD_BACK_LEFT_BIT;
143 }
144
145 if (mask)
146 _swrast_Clear( ctx, mask );
147 }
148
149 void __write_rgba_span24( const GLcontext *ctx, GLuint n, GLint x, GLint y,
150 const GLubyte rgba[][4], const GLubyte mask[] )
151 {
152 int i;
153 if (mask) {
154 /* draw some pixels */
155 for (i=0; i<n; i++, x++) {
156 if (mask[i]) {
157 __svga_drawpixel24( x, y, rgba[i][RCOMP],
158 rgba[i][GCOMP],
159 rgba[i][BCOMP]);
160 }
161 }
162 }
163 else {
164 /* draw all pixels */
165 for (i=0; i<n; i++, x++) {
166 __svga_drawpixel24( x, y, rgba[i][RCOMP],
167 rgba[i][GCOMP],
168 rgba[i][BCOMP]);
169 }
170 }
171 }
172
173 void __write_mono_rgba_span24( const GLcontext *ctx,
174 GLuint n, GLint x, GLint y,
175 const GLchan color[4], const GLubyte mask[])
176 {
177 int i;
178 for (i=0; i<n; i++, x++) {
179 if (mask[i]) {
180 __svga_drawpixel24( x, y, color[RCOMP], color[GCOMP], color[BCOMP]);
181 }
182 }
183 }
184
185 void __read_rgba_span24( const GLcontext *ctx, GLuint n, GLint x, GLint y,
186 GLubyte rgba[][4] )
187 {
188 int i;
189 for (i=0; i<n; i++, x++) {
190 *((GLint*)rgba[i]) = RGB2BGR24(__svga_getpixel24( x, y));
191 }
192 }
193
194 void __write_rgba_pixels24( const GLcontext *ctx,
195 GLuint n, const GLint x[], const GLint y[],
196 const GLubyte rgba[][4], const GLubyte mask[] )
197 {
198 int i;
199 for (i=0; i<n; i++) {
200 if (mask[i]) {
201 __svga_drawpixel24( x[i], y[i], rgba[i][RCOMP],
202 rgba[i][GCOMP],
203 rgba[i][BCOMP]);
204 }
205 }
206 }
207
208 void __write_mono_rgba_pixels24( const GLcontext *ctx,
209 GLuint n,
210 const GLint x[], const GLint y[],
211 const GLchan color[4], const GLubyte mask[] )
212 {
213 int i;
214 for (i=0; i<n; i++) {
215 if (mask[i]) {
216 __svga_drawpixel24( x[i], y[i],
217 color[RCOMP], color[GCOMP], color[BCOMP] );
218 }
219 }
220 }
221
222 void __read_rgba_pixels24( const GLcontext *ctx,
223 GLuint n, const GLint x[], const GLint y[],
224 GLubyte rgba[][4], const GLubyte mask[] )
225 {
226 int i;
227 for (i=0; i<n; i++,x++) {
228 *((GLint*)rgba[i]) = RGB2BGR24(__svga_getpixel24( x[i], y[i]));
229 }
230 }
231
232 #else
233
234
235 /* silence compiler warning */
236 extern void _mesa_svga24_dummy_function(void);
237 void _mesa_svga24_dummy_function(void)
238 {
239 }
240
241
242 #endif