3 * Copyright (C) 1997 Uwe Maurer
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.
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.
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:
21 * svgamesa.c and ddsample.c by Brian Paul
25 #include <ggi/mesa/ggimesa.h>
26 #include <ggi/mesa/ggimesa_int.h>
27 #include <ggi/mesa/debug.h>
28 #include "swrast/swrast.h"
30 #define RMASK ((1<<R)-1)
31 #define GMASK ((1<<G)-1)
32 #define BMASK ((1<<B)-1)
38 #define PACK(color) (((color[RCOMP]>>RS) << (G+B)) | \
39 ((color[GCOMP]>>GS) << B) | \
42 #define FLIP(coord) (LIBGGI_VIRTY(ggi_ctx->ggi_visual) - (coord) - 1)
45 /**********************************************************************/
46 /***** Write spans of pixels *****/
47 /**********************************************************************/
49 void GGIwrite_ci32_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
50 const GLuint ci
[], const GLubyte mask
[])
52 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
54 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
55 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
65 while (n
--) *fb
++ = *ci
++;
69 void GGIwrite_ci8_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
70 const GLubyte ci
[], const GLubyte mask
[])
72 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
74 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
75 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
85 while (n
--) *fb
++ = *ci
++;
90 void GGIwrite_rgba_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
91 const GLchan rgba
[][4], const GLubyte mask
[])
93 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
95 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
96 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
107 *fb
++ = PACK(rgba
[0]);
113 void GGIwrite_rgb_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
114 const GLchan rgba
[][3], const GLubyte mask
[])
116 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
118 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
119 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
130 *fb
++ = PACK(rgba
[0]);
137 void GGIwrite_mono_rgba_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
138 const GLchan color
[4], const GLubyte mask
[])
140 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
142 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
143 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
155 /* Alternatively we could write a potentialy faster HLine
156 ggiSetGCForeground(ggi_ctx->ggi_visual, color);
157 ggiDrawHLine(ggi_ctx->ggi_visual,x,FLIP(y),n);
162 void GGIwrite_mono_ci_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
163 const GLuint ci
, const GLubyte mask
[])
165 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
167 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
168 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
180 /* Alternatively we could write a potentialy faster HLine
181 ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
182 ggiDrawHLine(ggi_ctx->ggi_visual, x, FLIP(y), n);
188 /**********************************************************************/
189 /***** Read spans of pixels *****/
190 /**********************************************************************/
193 void GGIread_ci32_span(const GLcontext
*ctx
,
194 GLuint n
, GLint x
, GLint y
, GLuint ci
[])
196 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
198 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
199 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
202 *ci
++ = (GLuint
)*fb
++;
205 void GGIread_rgba_span(const GLcontext
*ctx
,
206 GLuint n
, GLint x
, GLint y
, GLchan rgba
[][4])
208 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
211 fb
= (FB_TYPE
*)((char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
212 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
216 rgba
[0][RCOMP
] = (GLubyte
) (color
>>(G
+B
))<<RS
;
217 rgba
[0][GCOMP
] = (GLubyte
) ((color
>>B
)& ((1<<G
)-1))<<GS
;
218 rgba
[0][BCOMP
] = (GLubyte
) (color
& ((1<<B
)-1))<<BS
;
224 /**********************************************************************/
225 /***** Write arrays of pixels *****/
226 /**********************************************************************/
228 void GGIwrite_ci32_pixels(const GLcontext
*ctx
,
229 GLuint n
, const GLint x
[], const GLint y
[],
230 const GLuint ci
[], const GLubyte mask
[])
232 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
233 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
234 char *fb
= (char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
238 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
247 void GGIwrite_mono_ci_pixels(const GLcontext
*ctx
,
248 GLuint n
, const GLint x
[], const GLint y
[],
249 GLuint ci
, const GLubyte mask
[])
251 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
252 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
253 char *fb
= (char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
257 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
265 void GGIwrite_rgba_pixels(const GLcontext
*ctx
,
266 GLuint n
, const GLint x
[], const GLint y
[],
267 const GLchan rgba
[][4], const GLubyte mask
[])
269 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
270 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
271 char *fb
= (char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
275 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
276 *dst
= PACK(rgba
[0]);
284 void GGIwrite_mono_rgba_pixels(const GLcontext
*ctx
,
285 GLuint n
, const GLint x
[], const GLint y
[],
286 const GLchan rgba
[4], const GLubyte mask
[])
288 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
289 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
290 char *fb
= (char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
294 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
303 /**********************************************************************/
304 /***** Read arrays of pixels *****/
305 /**********************************************************************/
307 void GGIread_ci32_pixels(const GLcontext
*ctx
,
308 GLuint n
, const GLint x
[], const GLint y
[],
309 GLuint ci
[], const GLubyte mask
[])
311 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
312 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
313 char *fb
= (char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
317 FB_TYPE
*src
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
326 void GGIread_rgba_pixels(const GLcontext
*ctx
,
327 GLuint n
, const GLint x
[], const GLint y
[],
328 GLubyte rgba
[][4], const GLubyte mask
[])
330 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
331 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
332 char *fb
= (char *)LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
337 FB_TYPE
*src
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
340 rgba
[0][RCOMP
] = (GLubyte
)(color
>>(G
+B
))<<RS
;
341 rgba
[0][GCOMP
] = (GLubyte
)((color
>>B
)& ((1<<G
)-1))<<GS
;
342 rgba
[0][BCOMP
] = (GLubyte
) (color
& ((1<<B
)-1))<<BS
;
351 void GGIset_buffer(GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
355 int GGIsetup_driver(ggi_mesa_context_t ggi_ctx
)
357 struct swrast_device_driver
*swdd
=
358 _swrast_GetDeviceDriverReference(ggi_ctx
->gl_ctx
);
360 GGIMESADPRINT_LIBS("linear_%d: GGIsetup_driver\n", sizeof(FB_TYPE
)*8);
362 swdd
->WriteRGBASpan
= GGIwrite_rgba_span
;
363 swdd
->WriteRGBSpan
= GGIwrite_rgb_span
;
364 swdd
->WriteMonoRGBASpan
= GGIwrite_mono_rgba_span
;
365 swdd
->WriteRGBAPixels
= GGIwrite_rgba_pixels
;
366 swdd
->WriteMonoRGBAPixels
= GGIwrite_mono_rgba_pixels
;
368 swdd
->WriteCI32Span
= GGIwrite_ci32_span
;
369 swdd
->WriteCI8Span
= GGIwrite_ci8_span
;
370 swdd
->WriteMonoCISpan
= GGIwrite_mono_ci_span
;
371 swdd
->WriteCI32Pixels
= GGIwrite_ci32_pixels
;
372 swdd
->WriteMonoCIPixels
= GGIwrite_mono_ci_pixels
;
374 swdd
->ReadCI32Span
= GGIread_ci32_span
;
375 swdd
->ReadRGBASpan
= GGIread_rgba_span
;
376 swdd
->ReadCI32Pixels
= GGIread_ci32_pixels
;
377 swdd
->ReadRGBAPixels
= GGIread_rgba_pixels
;
379 swdd
->SetBuffer
= GGIset_buffer
;
384 static int GGIopen(ggi_visual_t vis
,struct ggi_dlhandle
*dlh
,
385 const char *args
,void *argptr
, uint32
*dlret
)
387 GGIMESADPRINT_CORE("linear_%d: GGIOpen\n", sizeof(FB_TYPE
)*8);
388 LIBGGI_MESAEXT(vis
)->setup_driver
= GGIsetup_driver
;
390 *dlret
= GGI_DL_OPDRAW
;
394 int DLOPENFUNC(int func
, void **funcptr
)
407 return GGI_ENOTFOUND
;