* Auto* build fixes
[mesa.git] / src / mesa / drivers / ggi / default / linear.c
1 /* GGI-Driver for MESA
2 *
3 * Copyright (C) 1997 Uwe Maurer
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * ---------------------------------------------------------------------
19 * This code was derived from the following source of information:
20 *
21 * svgamesa.c and ddsample.c by Brian Paul
22 *
23 */
24
25 #include <ggi/mesa/ggimesa.h>
26 #include <ggi/mesa/ggimesa_int.h>
27
28 #define RMASK ((1<<R)-1)
29 #define GMASK ((1<<G)-1)
30 #define BMASK ((1<<B)-1)
31
32 #define RS (8-R)
33 #define GS (8-G)
34 #define BS (8-B)
35
36
37 /**********************************************************************/
38 /***** Write spans of pixels *****/
39 /**********************************************************************/
40
41 void GGIwrite_ci32_span(const GLcontext *ctx,
42 GLuint n, GLint x, GLint y,
43 const GLuint ci[],
44 const GLubyte mask[])
45 {
46 FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
47 if (mask)
48 {
49 while (n--) {
50 if (*mask++) *fb=*ci;
51 fb++;
52 ci++;
53 }
54 }
55 else
56 {
57 while (n--) *fb++ = *ci++;
58 }
59 }
60
61 void GGIwrite_ci8_span(const GLcontext *ctx,
62 GLuint n, GLint x, GLint y,
63 const GLubyte ci[],
64 const GLubyte mask[] )
65 {
66 FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
67
68 if (mask)
69 {
70 while (n--) {
71 if (*mask++) *fb=*ci;
72 fb++;
73 ci++;
74 }
75 }
76 else
77 {
78 while (n--) *fb++ = *ci++;
79 }
80 }
81
82
83 void GGIwrite_rgba_span(const GLcontext *ctx,
84 GLuint n, GLint x, GLint y,
85 const GLubyte rgba[][4],
86 const GLubyte mask[])
87 {
88 FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
89
90 if (mask)
91 {
92 while (n--) {
93 if (*mask++) {
94 *fb= ((rgba[0][RCOMP]>>RS) << (G+B)) |
95 ((rgba[0][GCOMP]>>GS) << B) |
96 ((rgba[0][BCOMP]>>BS));
97 }
98 fb++;
99 rgba++;
100 }
101 }
102 else
103 {
104 while (n--) {
105 *fb++= ((rgba[0][RCOMP]>>RS) << (G+B)) |
106 ((rgba[0][GCOMP]>>GS) << B)|
107 ((rgba[0][BCOMP]>>BS));
108 rgba++;
109 }
110 }
111 }
112
113 void GGIwrite_rgb_span( const GLcontext *ctx,
114 GLuint n, GLint x, GLint y,
115 const GLubyte rgba[][3],
116 const GLubyte mask[] )
117 {
118 FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
119 if (mask)
120 {
121 while (n--) {
122 if (*mask++) {
123 *fb= ((rgba[0][RCOMP]>>RS) << (G+B)) |
124 ((rgba[0][GCOMP]>>GS) << B) |
125 ((rgba[0][BCOMP]>>BS));
126 }
127 fb++;
128 rgba++;
129 }
130 }
131 else
132 {
133 while (n--) {
134 *fb++= ((rgba[0][RCOMP]>>RS) << (G+B)) |
135 ((rgba[0][GCOMP]>>GS) << B) |
136 ((rgba[0][BCOMP]>>BS));
137 rgba++;
138 }
139 }
140 }
141
142
143 void GGIwrite_mono_span( const GLcontext *ctx,
144 GLuint n, GLint x, GLint y,
145 const GLubyte mask[])
146 {
147 FB_TYPE *fb;
148 FB_TYPE color;
149
150 if (mask)
151 {
152 fb=LFB(FB_TYPE,x,FLIP(y));
153 color=(FB_TYPE) GGICTX->color;
154
155 while (n--)
156 {
157 if (*mask++) *fb=color;
158 fb++;
159 }
160 }
161 else
162 {
163 ggiDrawHLine(VIS,x,FLIP(y),n);
164 }
165 }
166
167
168 /**********************************************************************/
169 /***** Read spans of pixels *****/
170 /**********************************************************************/
171
172
173 void GGIread_ci32_span(const GLcontext *ctx,
174 GLuint n, GLint x, GLint y, GLuint ci[])
175 {
176 FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
177 while (n--)
178 *ci++=(GLuint)*fb++;
179 }
180
181 void GGIread_rgba_span(const GLcontext *ctx,
182 GLuint n, GLint x, GLint y,
183 GLubyte rgba[][4])
184 {
185 FB_TYPE *fb=LFB(FB_TYPE,x,FLIP(y));
186 FB_TYPE color;
187
188 while (n--)
189 {
190 color=*fb++;
191 rgba[0][RCOMP] = (GLubyte) (color>>(G+B))<<RS;
192 rgba[0][GCOMP] = (GLubyte) ((color>>B)& ((1<<G)-1))<<GS;
193 rgba[0][BCOMP] = (GLubyte) (color & ((1<<B)-1))<<BS;
194 rgba[0][ACOMP] =0;
195 rgba++;
196 }
197 }
198
199 /**********************************************************************/
200 /***** Write arrays of pixels *****/
201 /**********************************************************************/
202
203 void GGIwrite_ci32_pixels(const GLcontext *ctx,
204 GLuint n, const GLint x[], const GLint y[],
205 const GLuint ci[], const GLubyte mask[] )
206 {
207 FB_TYPE *fb=LFB(FB_TYPE,0,0);
208
209 while (n--) {
210 if (*mask++) *(fb+ *x + FLIP(*y)*GGICTX->width)=*ci;
211 ci++;
212 x++;
213 y++;
214 }
215 }
216
217 void GGIwrite_mono_pixels(const GLcontext *ctx,
218 GLuint n,
219 const GLint x[], const GLint y[],
220 const GLubyte mask[] )
221 {
222 FB_TYPE *fb=LFB(FB_TYPE,0,0);
223 FB_TYPE color=(FB_TYPE) GGICTX->color;
224
225 while (n--) {
226 if (*mask++) *(fb+ *x + FLIP(*y)*GGICTX->width)=color;
227 x++;
228 y++;
229 }
230 }
231
232 void GGIwrite_rgba_pixels(const GLcontext *ctx,
233 GLuint n, const GLint x[], const GLint y[],
234 const GLubyte rgba[][4],
235 const GLubyte mask[] )
236 {
237 FB_TYPE *fb=LFB(FB_TYPE,0,0);
238 FB_TYPE color;
239
240 while (n--) {
241 if (*mask++) {
242 color= ((rgba[0][RCOMP]>>RS) << (G+B)) |
243 ((rgba[0][GCOMP]>>GS) << B) |
244 ((rgba[0][BCOMP]>>BS));
245 *(fb+ *x + FLIP(*y)*GGICTX->width)=color;
246 }
247 x++;y++;
248 rgba++;
249 }
250 }
251
252
253 /**********************************************************************/
254 /***** Read arrays of pixels *****/
255 /**********************************************************************/
256
257 void GGIread_ci32_pixels(const GLcontext *ctx,
258 GLuint n, const GLint x[], const GLint y[],
259 GLuint ci[], const GLubyte mask[])
260 {
261 FB_TYPE *fb=LFB(FB_TYPE,0,0);
262
263 while (n--) {
264 if (*mask++)
265 *ci=*(fb+ *x + FLIP(*y)*GGICTX->width);
266 ci++;
267 x++;
268 y++;
269 }
270 }
271
272 void GGIread_rgba_pixels(const GLcontext *ctx,
273 GLuint n, const GLint x[], const GLint y[],
274 GLubyte rgba[][4],
275 const GLubyte mask[] )
276 {
277 FB_TYPE *fb=LFB(FB_TYPE,0,0);
278 FB_TYPE color;
279
280 while (n--)
281 {
282 if (*mask++)
283 {
284 color=*(fb+ *x + FLIP(*y)*GGICTX->width);
285 rgba[0][RCOMP] =(GLubyte)(color>>(G+B))<<RS;
286 rgba[0][GCOMP] =(GLubyte)((color>>B)& ((1<<G)-1))<<GS;
287 rgba[0][BCOMP] =(GLubyte) (color & ((1<<B)-1))<<BS;
288 rgba[0][ACOMP] =0;
289 }
290 x++; y++;
291 rgba++;
292 }
293 }
294
295 int GGIsetup_driver(GGIMesaContext ggictx, struct ggi_mesa_info *info)
296 {
297 GLcontext *ctx = ggictx->gl_ctx;
298
299 ctx->Driver.WriteRGBASpan = GGIwrite_rgba_span;
300 ctx->Driver.WriteRGBSpan = GGIwrite_rgb_span;
301 // ctx->Driver.WriteMonoRGBASpan = GGIwrite_mono_span;
302 ctx->Driver.WriteRGBAPixels = GGIwrite_rgba_pixels;
303 // ctx->Driver.WriteMonoRGBAPixels = GGIwrite_mono_pixels;
304
305 ctx->Driver.WriteCI32Span = GGIwrite_ci32_span;
306 ctx->Driver.WriteCI8Span = GGIwrite_ci8_span;
307 // ctx->Driver.WriteMonoCISpan = GGIwrite_mono_span;
308 ctx->Driver.WriteCI32Pixels = GGIwrite_ci32_pixels;
309 // ctx->Driver.WriteMonoCIPixels = GGIwrite_mono_pixels;
310
311 ctx->Driver.ReadCI32Span = GGIread_ci32_span;
312 ctx->Driver.ReadRGBASpan = GGIread_rgba_span;
313 ctx->Driver.ReadCI32Pixels = GGIread_ci32_pixels;
314 ctx->Driver.ReadRGBAPixels = GGIread_rgba_pixels;
315
316 info->red_bits = R;
317 info->green_bits =G;
318 info->blue_bits = B;
319
320 return 0;
321 }
322
323 static int GGIopen(ggi_visual_t vis,struct ggi_dlhandle *dlh,
324 const char *args,void *argptr, uint32 *dlret)
325 {
326 LIBGGI_MESAEXT(vis)->setup_driver=GGIsetup_driver;
327
328 *dlret = GGI_DL_OPDRAW;
329 return 0;
330 }
331
332 int DLOPENFUNC(int func, void **funcptr)
333 {
334 switch (func) {
335 case GGIFUNC_open:
336 *funcptr = GGIopen;
337 return 0;
338 case GGIFUNC_exit:
339 case GGIFUNC_close:
340 *funcptr = NULL;
341 return 0;
342 default:
343 *funcptr = NULL;
344 }
345 return GGI_ENOTFOUND;
346 }
347