]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/scr_bogl.x
Cleanup CVS ipmorted branch
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / scr_bogl.x
1 /*
2  * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
3  *
4  * Screen Driver using BOGL Library
5  *
6  * This driver now requires only the following BOGL entry points:
7  *      bogl_init, bogl_done, 
8  *      bogl_pixel, bogl_readpixel,
9  *      bogl_vline, bogl_hline
10  *
11  * All graphics drawing primitives are based on top of these functions.
12  *
13  * This file also contains the generalized low-level font/text
14  * drawing routines, which will be split out into another file.
15  * Both fixed and proportional fonts are supported, with fixed
16  * pitch structure allowing much smaller font files.
17  */
18 #include <stdio.h>
19 #include "../device.h"
20 #include "bogl/bogl.h"
21
22 /* specific bogl driver entry points*/
23 static int  BOGL_open(SCREENDEVICE *psd);
24 static void BOGL_close(void);
25 static void BOGL_getscreeninfo(PSCREENINFO psi);
26 static void BOGL_setpalette(int first,int count,RGBENTRY *pal);
27 static void BOGL_drawpixel(COORD x, COORD y, PIXELVAL c);
28 static PIXELVAL BOGL_readpixel(COORD x, COORD y);
29 static void BOGL_drawhline(COORD x1, COORD x2, COORD y, PIXELVAL c);
30 static void BOGL_drawvline(COORD x, COORD y1, COORD y2, PIXELVAL c);
31 static void BOGL_fillrect(COORD x1, COORD y1, COORD x2, COORD y2, PIXELVAL c);
32
33 /* generalized text/font routines*/
34 static BOOL gen_getfontinfo(FONTID fontid,PFONTINFO pfontinfo);
35 static void gen_gettextsize(const UCHAR *str,int cc,COORD *retwd,
36                 COORD *retht,FONTID fontid);
37 static void gen_gettextbits(UCHAR ch,IMAGEBITS *retmap,COORD *retwd,
38                 COORD *retht,FONTID fontid);
39 /*static void gen_drawtext(COORD x, COORD y, const UCHAR *s, int n,
40                         PIXELVAL fg, FONTID fontid);
41 static void gen_drawbitmap(COORD x, COORD y, COORD width, COORD height,
42                         IMAGEBITS *table, PIXELVAL fgcolor);*/
43
44 SCREENDEVICE    scrdev = {
45         BOGL_open,
46         BOGL_close,
47         BOGL_getscreeninfo,
48         BOGL_setpalette,
49         BOGL_drawpixel,
50         BOGL_readpixel,
51         BOGL_drawhline,
52         BOGL_drawvline,
53         BOGL_fillrect,
54         gen_getfontinfo,
55         gen_gettextsize,
56         gen_gettextbits,
57         640, 480, 256, PF_PALETTE
58 };
59
60 /* compiled in fonts*/
61 #define NUMBER_FONTS    3
62 extern FONT font_rom8x16, font_rom8x8;
63 extern FONT font_winFreeSansSerif11x13;
64 extern FONT font_winFreeSystem14x16;
65 extern FONT font_winSystem14x16;
66 extern FONT font_winMSSansSerif11x13;
67 extern FONT font_winTerminal8x12;
68 extern FONT font_helvB10, font_helvB12, font_helvR10;
69
70 /* first font is default font*/
71 PFONT fonts[NUMBER_FONTS] = {
72 #if HAVEMSFONTS
73         &font_winSystem14x16,           /* FONT_SYSTEM_VAR*/
74         &font_winMSSansSerif11x13,      /* FONT_GUI_VAR*/
75         &font_winTerminal8x12           /* FONT_OEM_FIXED*/
76 #else
77         &font_winFreeSystem14x16,       /* FONT_SYSTEM_VAR*/
78         &font_winFreeSansSerif11x13,    /* FONT_GUI_VAR*/
79         &font_rom8x16                   /* FONT_OEM_FIXED*/
80 #endif
81 };
82
83 static int
84 BOGL_open(SCREENDEVICE *psd)
85 {
86         if(bogl_init() == 0)
87                 return -1;
88         psd->xres = bogl_xres;
89         psd->yres = bogl_yres;
90         psd->ncolors = bogl_ncols;
91
92         /* set pixel format*/
93         if(bogl_ncols > 256)
94                 psd->pixtype = PF_TRUECOLOR24;
95         else if(bogl_ncols == 256 && bogl_truecolor)
96                 psd->pixtype = PF_TRUECOLOR332;
97         else
98                 psd->pixtype = PF_PALETTE;
99         return 1;
100 }
101
102 static void
103 BOGL_close(void)
104 {
105         bogl_done();
106 }
107
108 static void
109 BOGL_getscreeninfo(PSCREENINFO psi)
110 {
111         psi->rows = scrdev.yres;
112         psi->cols = scrdev.xres;
113         psi->ncolors = scrdev.ncolors;
114         psi->pixtype = scrdev.pixtype;
115         psi->black = 0;
116         psi->white = 15;
117         psi->fonts = NUMBER_FONTS;
118
119         if(scrdev.yres > 480) {
120                 /* SVGA 800x600*/
121                 psi->xdpcm = 33;        /* assumes screen width of 24 cm*/
122                 psi->ydpcm = 33;        /* assumes screen height of 18 cm*/
123         } else if(scrdev.yres > 350) {
124                 /* VGA 640x480*/
125                 psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
126                 psi->ydpcm = 27;        /* assumes screen height of 18 cm*/
127         } else {
128                 /* EGA 640x350*/
129                 psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
130                 psi->ydpcm = 19;        /* assumes screen height of 18 cm*/
131         }
132 }
133
134 /*
135  * Set count palette entries starting from first
136  */
137 static void
138 BOGL_setpalette(int first,int count,RGBENTRY *pal)
139 {
140         bogl_set_palette(first, count, (void*)pal);
141 }
142
143 static void
144 BOGL_drawpixel(COORD x, COORD y, PIXELVAL c)
145 {
146         bogl_pixel(x, y, c);
147 }
148
149 static PIXELVAL
150 BOGL_readpixel(COORD x, COORD y)
151 {
152         return bogl_readpixel(x, y);
153 }
154
155 static void
156 BOGL_drawhline(COORD x1, COORD x2, COORD y, PIXELVAL c)
157 {
158         /*
159          * bogl uses type 2 line drawing, the last point is not drawn
160          */
161         bogl_hline(x1, x2+1, y, c);
162
163         /*
164          * Uncomment the following if driver doesn't support hline
165         while(x1 <= x2)
166                 bogl_pixel(x1++, y, c);
167          */
168 }
169
170 static void
171 BOGL_drawvline(COORD x, COORD y1, COORD y2, PIXELVAL c)
172 {
173         /*
174          * bogl uses type 2 line drawing, the last point is not drawn
175          */
176         bogl_vline(x, y1, y2+1, c);
177
178         /*
179          * Uncomment the following if driver doesn't support vline
180         while(y1 <= y2)
181                 bogl_pixel(x, y1++, c);
182          */
183 }
184
185 static void
186 BOGL_fillrect(COORD x1, COORD y1, COORD x2, COORD y2, PIXELVAL c)
187 {
188         /*
189          * Call bogl hline (type 2) to save size
190          */
191         ++x2;           /* fix bogl last point not drawn*/
192         while(y1 <= y2)
193                 bogl_hline(x1, x2, y1++, c);
194         /*
195          * Uncomment the following if driver doesn't support fillrect
196         while(y1 <= y2)
197                 BOGL_drawhline(x1, x2, y1++, c);
198          */
199 }
200
201 #if 0000
202 /* 
203  * Generalized low level text draw routine, called only
204  * if no clipping is required
205  */
206 static void
207 gen_drawtext(COORD x,COORD y,const UCHAR *s,int n,PIXELVAL fg,FONTID fontid)
208 {
209         COORD           width;                  /* width of character */
210         COORD           height;                 /* height of character */
211         PFONT           pf;
212         IMAGEBITS       bitmap[MAX_CHAR_HEIGHT];/* bitmap for character */
213
214         if(fontid >= NUMBER_FONTS)
215                 return;
216         pf = fonts[fontid];
217
218         /* x, y is bottom left corner*/
219         y -= pf->height - 1;
220         while (n-- > 0) {
221                 gen_gettextbits(*s++, bitmap, &width, &height, pf);
222                 gen_drawbitmap(x, y, width, height, bitmap, fg);
223                 x += width;
224         }
225 }
226
227 /*
228  * Generalized low level bitmap output routine, called
229  * only if no clipping is required.  Only the set bits
230  * in the bitmap are drawn, in the foreground color.
231  */
232 static void
233 gen_drawbitmap(COORD x, COORD y, COORD width, COORD height, IMAGEBITS *table,
234         PIXELVAL fgcolor)
235 {
236   COORD minx;
237   COORD maxx;
238   IMAGEBITS bitvalue;   /* bitmap word value */
239   int bitcount;                 /* number of bits left in bitmap word */
240
241   minx = x;
242   maxx = x + width - 1;
243   bitcount = 0;
244   while (height > 0) {
245         if (bitcount <= 0) {
246                 bitcount = IMAGE_BITSPERIMAGE;
247                 bitvalue = *table++;
248         }
249         if (IMAGE_TESTBIT(bitvalue))
250                 BOGL_drawpixel(x, y, fgcolor);
251         bitvalue = IMAGE_SHIFTBIT(bitvalue);
252         --bitcount;
253         if (x++ == maxx) {
254                 x = minx;
255                 ++y;
256                 --height;
257                 bitcount = 0;
258         }
259   }
260 }
261 #endif
262
263 /*
264  * Generalized low level get font info routine.  This
265  * routine works with fixed and proportional fonts.
266  */
267 static BOOL
268 gen_getfontinfo(FONTID fontid,PFONTINFO pfontinfo)
269 {
270         PFONT   pf;
271         int     i;
272
273         if(fontid >= NUMBER_FONTS)
274                 return FALSE;
275         pf = fonts[fontid];
276
277         pfontinfo->font = fontid;
278         pfontinfo->height = pf->height;
279         pfontinfo->maxwidth = pf->maxwidth;
280         pfontinfo->baseline = 0;
281         pfontinfo->fixed = pf->width == NULL? TRUE: FALSE;
282         for(i=0; i<256; ++i) {
283                 if(pf->width == NULL)
284                         pfontinfo->widths[i] = pf->maxwidth;
285                 else {
286                         if(i<pf->firstchar || i >= pf->firstchar+pf->size)
287                                 pfontinfo->widths[i] = 0;
288                         else pfontinfo->widths[i] = pf->width[i-pf->firstchar];
289                 }
290         }
291         return TRUE;
292 }
293
294 /*
295  * Generalized low level routine to calc bounding box for text output.
296  * Handles both fixed and proportional fonts.
297  */
298 static void
299 gen_gettextsize(const UCHAR *str,int cc,COORD *retwd,COORD *retht,
300         FONTID fontid)
301 {
302         PFONT   pf;
303         int     c;
304         int     width;
305
306         if(fontid >= NUMBER_FONTS) {
307                 *retht = 0;
308                 *retwd = 0;
309                 return;
310         }
311         pf = fonts[fontid];
312
313         if(pf->width == NULL)
314                 width = cc * pf->maxwidth;
315         else {
316                 width = 0;
317                 while(--cc >= 0) {
318                         if( (c = *str++) >= pf->firstchar &&
319                              c < pf->firstchar+pf->size)
320                                 width += pf->width[c - pf->firstchar];
321                 }
322         }
323
324         *retwd = width;
325         *retht = pf->height;
326
327 }
328
329 /*
330  * Generalized low level routine to get the bitmap associated
331  * with a character.  Handles fixed and proportional fonts.
332  */
333 static void
334 gen_gettextbits(UCHAR ch,IMAGEBITS *retmap,COORD *retwd, COORD *retht,
335         FONTID fontid)
336 {
337         int             n;
338         PFONT           pf = NULL;
339         IMAGEBITS *     bits;
340
341         if(fontid < NUMBER_FONTS)
342                 pf = fonts[fontid];
343
344         if(!pf || ch < pf->firstchar || ch >= pf->firstchar+pf->size) {
345                 *retht = 0;
346                 *retwd = 0;
347                 return;
348         }
349         ch -= pf->firstchar;
350
351         /* get font bitmap depending on fixed pitch or not*/
352         bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
353         for(n=0; n<pf->height; ++n)
354                 *retmap++ = *bits++;
355
356         /* return width depending on fixed pitch or not*/
357         *retwd = pf->width? pf->width[ch]: pf->maxwidth;
358         *retht = pf->height;
359 }
360
361 #if 0
362 static unsigned char palette[16+16][3] = {
363   /* Linux 16 color palette*/
364   { 0x00,0x00,0x00 },
365   { 0x00,0x00,0xaa },
366   { 0x00,0xaa,0x00 },
367   { 0x00,0xaa,0xaa },
368   { 0xaa,0x00,0x00 },
369   { 0xaa,0x00,0xaa },
370   { 0xaa,0x55,0x00 },   /* adjust to brown*/
371   //{ 0xaa,0xaa,0x00 },
372   { 0xaa,0xaa,0xaa },
373   { 0x55,0x55,0x55 },
374   { 0x55,0x55,0xff },
375   { 0x55,0xff,0x55 },
376   { 0x55,0xff,0xff },
377   { 0xff,0x55,0x55 },
378   { 0xff,0x55,0xff },
379   { 0xff,0xff,0x55 },
380   { 0xff,0xff,0xff },
381
382   /* 16 entry std palette*/
383   {0x00, 0x00, 0x00},
384   {0x00, 0x00, 0xbf},
385   {0x00, 0xbf, 0x00},
386   {0x00, 0xbf, 0xbf},
387   {0xbf, 0x00, 0x00},
388   {0xbf, 0x00, 0xbf},
389   {0xbf, 0x60, 0x00},   /* adjust to brown*/
390   //{0xbf, 0xbf, 0x00},
391   {0xc0, 0xc0, 0xc0},
392   {0x80, 0x80, 0x80},
393   {0x00, 0x00, 0xff},
394   {0x00, 0xff, 0x00},
395   {0x00, 0xff, 0xff},
396   {0xff, 0x00, 0x00},
397   {0xff, 0x00, 0xff},
398   {0xff, 0xff, 0x00},
399   {0xff, 0xff, 0xff},
400 };
401 #endif