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_MODE(ggi_ctx->ggi_visual)->visible.y-(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
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
55 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
68 while (n
--) *fb
++ = *ci
++;
72 void GGIwrite_ci8_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
73 const GLubyte ci
[], const GLubyte mask
[])
75 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
77 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
78 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
91 while (n
--) *fb
++ = *ci
++;
96 void GGIwrite_rgba_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
97 const GLchan rgba
[][4], const GLubyte mask
[])
99 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
101 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
102 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
116 *fb
++ = PACK(rgba
[0]);
122 void GGIwrite_rgb_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
123 const GLchan rgba
[][3], const GLubyte mask
[])
125 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
127 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
128 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
142 *fb
++ = PACK(rgba
[0]);
149 void GGIwrite_mono_rgba_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
150 const GLchan color
[4], const GLubyte mask
[])
152 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
154 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
155 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
168 /* Alternatively we could write a potentialy faster HLine
169 ggiSetGCForeground(ggi_ctx->ggi_visual, color);
170 ggiDrawHLine(ggi_ctx->ggi_visual,x,FLIP(y),n);
175 void GGIwrite_mono_ci_span(const GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
176 const GLuint ci
, const GLubyte mask
[])
178 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
180 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
181 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
194 /* Alternatively we could write a potentialy faster HLine
195 ggiSetGCForeground(ggi_ctx->ggi_visual, ci);
196 ggiDrawHLine(ggi_ctx->ggi_visual, x, FLIP(y), n);
202 /**********************************************************************/
203 /***** Read spans of pixels *****/
204 /**********************************************************************/
207 void GGIread_ci32_span(const GLcontext
*ctx
,
208 GLuint n
, GLint x
, GLint y
, GLuint ci
[])
210 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
212 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
213 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
216 *ci
++ = (GLuint
)*fb
++;
219 void GGIread_rgba_span(const GLcontext
*ctx
,
220 GLuint n
, GLint x
, GLint y
, GLchan rgba
[][4])
222 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
225 fb
= (FB_TYPE
*)(LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
) +
226 FLIP(y
)*LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
)) + x
;
231 rgba
[0][RCOMP
] = (GLubyte
) (color
>>(G
+B
))<<RS
;
232 rgba
[0][GCOMP
] = (GLubyte
) ((color
>>B
)& ((1<<G
)-1))<<GS
;
233 rgba
[0][BCOMP
] = (GLubyte
) (color
& ((1<<B
)-1))<<BS
;
239 /**********************************************************************/
240 /***** Write arrays of pixels *****/
241 /**********************************************************************/
243 void GGIwrite_ci32_pixels(const GLcontext
*ctx
,
244 GLuint n
, const GLint x
[], const GLint y
[],
245 const GLuint ci
[], const GLubyte mask
[])
247 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
248 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
249 void *fb
= LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
253 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
262 void GGIwrite_mono_ci_pixels(const GLcontext
*ctx
,
263 GLuint n
, const GLint x
[], const GLint y
[],
264 GLuint ci
, const GLubyte mask
[])
266 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
267 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
268 void *fb
= LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
272 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
280 void GGIwrite_rgba_pixels(const GLcontext
*ctx
,
281 GLuint n
, const GLint x
[], const GLint y
[],
282 const GLchan rgba
[][4], const GLubyte mask
[])
284 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
285 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
286 void *fb
= LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
290 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
291 *dst
= PACK(rgba
[0]);
299 void GGIwrite_mono_rgba_pixels(const GLcontext
*ctx
,
300 GLuint n
, const GLint x
[], const GLint y
[],
301 const GLchan rgba
[4], const GLubyte mask
[])
303 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
304 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
305 void *fb
= LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
309 FB_TYPE
*dst
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
318 /**********************************************************************/
319 /***** Read arrays of pixels *****/
320 /**********************************************************************/
322 void GGIread_ci32_pixels(const GLcontext
*ctx
,
323 GLuint n
, const GLint x
[], const GLint y
[],
324 GLuint ci
[], const GLubyte mask
[])
326 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
327 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
328 void *fb
= LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
332 FB_TYPE
*src
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
341 void GGIread_rgba_pixels(const GLcontext
*ctx
,
342 GLuint n
, const GLint x
[], const GLint y
[],
343 GLubyte rgba
[][4], const GLubyte mask
[])
345 ggi_mesa_context_t ggi_ctx
= (ggi_mesa_context_t
)ctx
->DriverCtx
;
346 int stride
= LIBGGI_FB_W_STRIDE(ggi_ctx
->ggi_visual
);
347 void *fb
= LIBGGI_CURWRITE(ggi_ctx
->ggi_visual
);
354 FB_TYPE
*src
= (FB_TYPE
*)(fb
+ FLIP(*y
)*stride
) + *x
;
357 rgba
[0][RCOMP
] = (GLubyte
)(color
>>(G
+B
))<<RS
;
358 rgba
[0][GCOMP
] = (GLubyte
)((color
>>B
)& ((1<<G
)-1))<<GS
;
359 rgba
[0][BCOMP
] = (GLubyte
) (color
& ((1<<B
)-1))<<BS
;
368 void GGIset_buffer(GLcontext
*ctx
, GLframebuffer
*buffer
, GLenum mode
)
372 int GGIsetup_driver(ggi_mesa_context_t ggi_ctx
)
374 struct swrast_device_driver
*swdd
=
375 _swrast_GetDeviceDriverReference(ggi_ctx
->gl_ctx
);
377 GGIMESADPRINT_LIBS("linear_%d: GGIsetup_driver\n", sizeof(FB_TYPE
)*8);
379 swdd
->WriteRGBASpan
= GGIwrite_rgba_span
;
380 swdd
->WriteRGBSpan
= GGIwrite_rgb_span
;
381 swdd
->WriteMonoRGBASpan
= GGIwrite_mono_rgba_span
;
382 swdd
->WriteRGBAPixels
= GGIwrite_rgba_pixels
;
383 swdd
->WriteMonoRGBAPixels
= GGIwrite_mono_rgba_pixels
;
385 swdd
->WriteCI32Span
= GGIwrite_ci32_span
;
386 swdd
->WriteCI8Span
= GGIwrite_ci8_span
;
387 swdd
->WriteMonoCISpan
= GGIwrite_mono_ci_span
;
388 swdd
->WriteCI32Pixels
= GGIwrite_ci32_pixels
;
389 swdd
->WriteMonoCIPixels
= GGIwrite_mono_ci_pixels
;
391 swdd
->ReadCI32Span
= GGIread_ci32_span
;
392 swdd
->ReadRGBASpan
= GGIread_rgba_span
;
393 swdd
->ReadCI32Pixels
= GGIread_ci32_pixels
;
394 swdd
->ReadRGBAPixels
= GGIread_rgba_pixels
;
396 swdd
->SetBuffer
= GGIset_buffer
;
401 static int GGIopen(ggi_visual_t vis
,struct ggi_dlhandle
*dlh
,
402 const char *args
,void *argptr
, uint32
*dlret
)
404 GGIMESADPRINT_CORE("linear_%d: GGIOpen\n", sizeof(FB_TYPE
)*8);
405 LIBGGI_MESAEXT(vis
)->setup_driver
= GGIsetup_driver
;
407 *dlret
= GGI_DL_OPDRAW
;
411 int DLOPENFUNC(int func
, void **funcptr
)
424 return GGI_ENOTFOUND
;