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