[BACK]Return to rasops1.c CVS log [TXT][DIR] Up to [local] / sys / dev / rasops

Annotation of sys/dev/rasops/rasops1.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: rasops1.c,v 1.5 2006/08/03 18:42:06 miod Exp $        */
        !             2: /*     $NetBSD: rasops1.c,v 1.11 2000/04/12 14:22:29 pk Exp $  */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 1999 The NetBSD Foundation, Inc.
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * This code is derived from software contributed to The NetBSD Foundation
        !             9:  * by Andrew Doran.
        !            10:  *
        !            11:  * Redistribution and use in source and binary forms, with or without
        !            12:  * modification, are permitted provided that the following conditions
        !            13:  * are met:
        !            14:  * 1. Redistributions of source code must retain the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *     This product includes software developed by the NetBSD
        !            22:  *     Foundation, Inc. and its contributors.
        !            23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            24:  *    contributors may be used to endorse or promote products derived
        !            25:  *    from this software without specific prior written permission.
        !            26:  *
        !            27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            37:  * POSSIBILITY OF SUCH DAMAGE.
        !            38:  */
        !            39:
        !            40: #include <sys/param.h>
        !            41: #include <sys/systm.h>
        !            42: #include <sys/time.h>
        !            43: #include <machine/endian.h>
        !            44:
        !            45: #include <dev/wscons/wsdisplayvar.h>
        !            46: #include <dev/wscons/wsconsio.h>
        !            47: #include <dev/rasops/rasops.h>
        !            48: #include <dev/rasops/rasops_masks.h>
        !            49:
        !            50: void   rasops1_copycols(void *, int, int, int, int);
        !            51: void   rasops1_erasecols(void *, int, int, int, long);
        !            52: void   rasops1_do_cursor(struct rasops_info *);
        !            53: void   rasops1_putchar(void *, int, int col, u_int, long);
        !            54: #ifndef RASOPS_SMALL
        !            55: void   rasops1_putchar8(void *, int, int col, u_int, long);
        !            56: void   rasops1_putchar16(void *, int, int col, u_int, long);
        !            57: #endif
        !            58:
        !            59: /*
        !            60:  * Initialize rasops_info struct for this colordepth.
        !            61:  */
        !            62: void
        !            63: rasops1_init(ri)
        !            64:        struct rasops_info *ri;
        !            65: {
        !            66:        rasops_masks_init();
        !            67:
        !            68:        switch (ri->ri_font->fontwidth) {
        !            69: #ifndef RASOPS_SMALL
        !            70:        case 8:
        !            71:                ri->ri_ops.putchar = rasops1_putchar8;
        !            72:                break;
        !            73:        case 16:
        !            74:                ri->ri_ops.putchar = rasops1_putchar16;
        !            75:                break;
        !            76: #endif
        !            77:        default:
        !            78:                ri->ri_ops.putchar = rasops1_putchar;
        !            79:                break;
        !            80:        }
        !            81:
        !            82:        if ((ri->ri_font->fontwidth & 7) != 0) {
        !            83:                ri->ri_ops.erasecols = rasops1_erasecols;
        !            84:                ri->ri_ops.copycols = rasops1_copycols;
        !            85:                ri->ri_do_cursor = rasops1_do_cursor;
        !            86:        }
        !            87: }
        !            88:
        !            89: /*
        !            90:  * Paint a single character. This is the generic version, this is ugly.
        !            91:  */
        !            92: void
        !            93: rasops1_putchar(cookie, row, col, uc, attr)
        !            94:        void *cookie;
        !            95:        int row, col;
        !            96:        u_int uc;
        !            97:        long attr;
        !            98: {
        !            99:        u_int fs, rs, fb, bg, fg, lmask, rmask;
        !           100:        u_int32_t height, width;
        !           101:        struct rasops_info *ri;
        !           102:        int32_t *rp;
        !           103:        u_char *fr;
        !           104:
        !           105:        ri = (struct rasops_info *)cookie;
        !           106:
        !           107: #ifdef RASOPS_CLIPPING
        !           108:        /* Catches 'row < 0' case too */
        !           109:        if ((unsigned)row >= (unsigned)ri->ri_rows)
        !           110:                return;
        !           111:
        !           112:        if ((unsigned)col >= (unsigned)ri->ri_cols)
        !           113:                return;
        !           114: #endif
        !           115:
        !           116:        col *= ri->ri_font->fontwidth;
        !           117:        rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
        !           118:        height = ri->ri_font->fontheight;
        !           119:        width = ri->ri_font->fontwidth;
        !           120:        col = col & 31;
        !           121:        rs = ri->ri_stride;
        !           122:
        !           123:        bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        !           124:        fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        !           125:
        !           126:        /* If fg and bg match this becomes a space character */
        !           127:        if (fg == bg || uc == ' ') {
        !           128:                uc = (u_int)-1;
        !           129:                fr = 0;         /* shutup gcc */
        !           130:                fs = 0;         /* shutup gcc */
        !           131:        } else {
        !           132:                uc -= ri->ri_font->firstchar;
        !           133:                fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
        !           134:                fs = ri->ri_font->stride;
        !           135:        }
        !           136:
        !           137:        /* Single word, one mask */
        !           138:        if ((col + width) <= 32) {
        !           139:                rmask = rasops_pmask[col][width];
        !           140:                lmask = ~rmask;
        !           141:
        !           142:                if (uc == (u_int)-1) {
        !           143:                        bg &= rmask;
        !           144:
        !           145:                        while (height--) {
        !           146:                                *rp = (*rp & lmask) | bg;
        !           147:                                DELTA(rp, rs, int32_t *);
        !           148:                        }
        !           149:                } else {
        !           150:                        /* NOT fontbits if bg is white */
        !           151:                        if (bg) {
        !           152:                                while (height--) {
        !           153:                                        fb = ~(fr[3] | (fr[2] << 8) |
        !           154:                                            (fr[1] << 16) | (fr[0] << 24));
        !           155:                                        *rp = (*rp & lmask)
        !           156:                                            | (MBE(fb >> col) & rmask);
        !           157:
        !           158:                                        fr += fs;
        !           159:                                        DELTA(rp, rs, int32_t *);
        !           160:                                }
        !           161:                        } else {
        !           162:                                while (height--) {
        !           163:                                        fb = (fr[3] | (fr[2] << 8) |
        !           164:                                            (fr[1] << 16) | (fr[0] << 24));
        !           165:                                        *rp = (*rp & lmask)
        !           166:                                            | (MBE(fb >> col) & rmask);
        !           167:
        !           168:                                        fr += fs;
        !           169:                                        DELTA(rp, rs, int32_t *);
        !           170:                                }
        !           171:                        }
        !           172:                }
        !           173:
        !           174:                /* Do underline */
        !           175:                if ((attr & 1) != 0) {
        !           176:                        DELTA(rp, -(ri->ri_stride << 1), int32_t *);
        !           177:                        *rp = (*rp & lmask) | (fg & rmask);
        !           178:                }
        !           179:        } else {
        !           180:                lmask = ~rasops_lmask[col];
        !           181:                rmask = ~rasops_rmask[(col + width) & 31];
        !           182:
        !           183:                if (uc == (u_int)-1) {
        !           184:                        width = bg & ~rmask;
        !           185:                        bg = bg & ~lmask;
        !           186:
        !           187:                        while (height--) {
        !           188:                                rp[0] = (rp[0] & lmask) | bg;
        !           189:                                rp[1] = (rp[1] & rmask) | width;
        !           190:                                DELTA(rp, rs, int32_t *);
        !           191:                        }
        !           192:                } else {
        !           193:                        width = 32 - col;
        !           194:
        !           195:                        /* NOT fontbits if bg is white */
        !           196:                        if (bg) {
        !           197:                                while (height--) {
        !           198:                                        fb = ~(fr[3] | (fr[2] << 8) |
        !           199:                                            (fr[1] << 16) | (fr[0] << 24));
        !           200:
        !           201:                                        rp[0] = (rp[0] & lmask)
        !           202:                                            | MBE((u_int)fb >> col);
        !           203:
        !           204:                                        rp[1] = (rp[1] & rmask)
        !           205:                                            | (MBE((u_int)fb << width) & ~rmask);
        !           206:
        !           207:                                        fr += fs;
        !           208:                                        DELTA(rp, rs, int32_t *);
        !           209:                                }
        !           210:                        } else {
        !           211:                                while (height--) {
        !           212:                                        fb = (fr[3] | (fr[2] << 8) |
        !           213:                                            (fr[1] << 16) | (fr[0] << 24));
        !           214:
        !           215:                                        rp[0] = (rp[0] & lmask)
        !           216:                                            | MBE(fb >> col);
        !           217:
        !           218:                                        rp[1] = (rp[1] & rmask)
        !           219:                                            | (MBE(fb << width) & ~rmask);
        !           220:
        !           221:                                        fr += fs;
        !           222:                                        DELTA(rp, rs, int32_t *);
        !           223:                                }
        !           224:                        }
        !           225:                }
        !           226:
        !           227:                /* Do underline */
        !           228:                if ((attr & 1) != 0) {
        !           229:                        DELTA(rp, -(ri->ri_stride << 1), int32_t *);
        !           230:                        rp[0] = (rp[0] & lmask) | (fg & ~lmask);
        !           231:                        rp[1] = (rp[1] & rmask) | (fg & ~rmask);
        !           232:                }
        !           233:        }
        !           234: }
        !           235:
        !           236: #ifndef RASOPS_SMALL
        !           237: /*
        !           238:  * Paint a single character. This is for 8-pixel wide fonts.
        !           239:  */
        !           240: void
        !           241: rasops1_putchar8(cookie, row, col, uc, attr)
        !           242:        void *cookie;
        !           243:        int row, col;
        !           244:        u_int uc;
        !           245:        long attr;
        !           246: {
        !           247:        int height, fs, rs, bg, fg;
        !           248:        struct rasops_info *ri;
        !           249:        u_char *fr, *rp;
        !           250:
        !           251:        ri = (struct rasops_info *)cookie;
        !           252:
        !           253: #ifdef RASOPS_CLIPPING
        !           254:        /* Catches 'row < 0' case too */
        !           255:        if ((unsigned)row >= (unsigned)ri->ri_rows)
        !           256:                return;
        !           257:
        !           258:        if ((unsigned)col >= (unsigned)ri->ri_cols)
        !           259:                return;
        !           260: #endif
        !           261:
        !           262:        rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
        !           263:        height = ri->ri_font->fontheight;
        !           264:        rs = ri->ri_stride;
        !           265:
        !           266:        bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        !           267:        fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        !           268:
        !           269:        /* If fg and bg match this becomes a space character */
        !           270:        if (fg == bg || uc == ' ') {
        !           271:                while (height--) {
        !           272:                        *rp = bg;
        !           273:                        rp += rs;
        !           274:                }
        !           275:        } else {
        !           276:                uc -= ri->ri_font->firstchar;
        !           277:                fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
        !           278:                fs = ri->ri_font->stride;
        !           279:
        !           280:                /* NOT fontbits if bg is white */
        !           281:                if (bg) {
        !           282:                        while (height--) {
        !           283:                                *rp = ~*fr;
        !           284:                                fr += fs;
        !           285:                                rp += rs;
        !           286:                        }
        !           287:                } else {
        !           288:                        while (height--) {
        !           289:                                *rp = *fr;
        !           290:                                fr += fs;
        !           291:                                rp += rs;
        !           292:                        }
        !           293:                }
        !           294:
        !           295:        }
        !           296:
        !           297:        /* Do underline */
        !           298:        if ((attr & 1) != 0)
        !           299:                rp[-(ri->ri_stride << 1)] = fg;
        !           300: }
        !           301:
        !           302: /*
        !           303:  * Paint a single character. This is for 16-pixel wide fonts.
        !           304:  */
        !           305: void
        !           306: rasops1_putchar16(cookie, row, col, uc, attr)
        !           307:        void *cookie;
        !           308:        int row, col;
        !           309:        u_int uc;
        !           310:        long attr;
        !           311: {
        !           312:        int height, fs, rs, bg, fg;
        !           313:        struct rasops_info *ri;
        !           314:        u_char *fr, *rp;
        !           315:
        !           316:        ri = (struct rasops_info *)cookie;
        !           317:
        !           318: #ifdef RASOPS_CLIPPING
        !           319:        /* Catches 'row < 0' case too */
        !           320:        if ((unsigned)row >= (unsigned)ri->ri_rows)
        !           321:                return;
        !           322:
        !           323:        if ((unsigned)col >= (unsigned)ri->ri_cols)
        !           324:                return;
        !           325: #endif
        !           326:
        !           327:        rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
        !           328:        height = ri->ri_font->fontheight;
        !           329:        rs = ri->ri_stride;
        !           330:
        !           331:        bg = (attr & 0x000f0000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        !           332:        fg = (attr & 0x0f000000) ? ri->ri_devcmap[1] : ri->ri_devcmap[0];
        !           333:
        !           334:        /* If fg and bg match this becomes a space character */
        !           335:        if (fg == bg || uc == ' ') {
        !           336:                while (height--) {
        !           337:                        *(int16_t *)rp = bg;
        !           338:                        rp += rs;
        !           339:                }
        !           340:        } else {
        !           341:                uc -= ri->ri_font->firstchar;
        !           342:                fr = (u_char *)ri->ri_font->data + uc * ri->ri_fontscale;
        !           343:                fs = ri->ri_font->stride;
        !           344:
        !           345:                /* NOT fontbits if bg is white */
        !           346:                if (bg) {
        !           347:                        while (height--) {
        !           348:                                rp[0] = ~fr[0];
        !           349:                                rp[1] = ~fr[1];
        !           350:                                fr += fs;
        !           351:                                rp += rs;
        !           352:                        }
        !           353:                } else {
        !           354:                        while (height--) {
        !           355:                                rp[0] = fr[0];
        !           356:                                rp[1] = fr[1];
        !           357:                                fr += fs;
        !           358:                                rp += rs;
        !           359:                        }
        !           360:                }
        !           361:        }
        !           362:
        !           363:        /* Do underline */
        !           364:        if ((attr & 1) != 0)
        !           365:                *(int16_t *)(rp - (ri->ri_stride << 1)) = fg;
        !           366: }
        !           367: #endif /* !RASOPS_SMALL */
        !           368:
        !           369: /*
        !           370:  * Grab routines common to depths where (bpp < 8)
        !           371:  */
        !           372: #define NAME(ident)    rasops1_##ident
        !           373: #define PIXEL_SHIFT    0
        !           374:
        !           375: #include <dev/rasops/rasops_bitops.h>

CVSweb