Home | History | Annotate | Line # | Download | only in rasops
rasops_putchar_width.h revision 1.3
      1  1.3  rin /* $NetBSD: rasops_putchar_width.h,v 1.3 2019/07/28 02:56:53 rin Exp $ */
      2  1.1  rin 
      3  1.1  rin /* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp  */
      4  1.1  rin /*-
      5  1.1  rin  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      6  1.1  rin  * All rights reserved.
      7  1.1  rin  *
      8  1.1  rin  * This code is derived from software contributed to The NetBSD Foundation
      9  1.1  rin  * by Andrew Doran.
     10  1.1  rin  *
     11  1.1  rin  * Redistribution and use in source and binary forms, with or without
     12  1.1  rin  * modification, are permitted provided that the following conditions
     13  1.1  rin  * are met:
     14  1.1  rin  * 1. Redistributions of source code must retain the above copyright
     15  1.1  rin  *    notice, this list of conditions and the following disclaimer.
     16  1.1  rin  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  rin  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  rin  *    documentation and/or other materials provided with the distribution.
     19  1.1  rin  *
     20  1.1  rin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1  rin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  rin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  rin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1  rin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  rin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  rin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  rin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  rin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  rin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  rin  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  rin  */
     32  1.1  rin 
     33  1.1  rin #if RASOPS_DEPTH != 8 && RASOPS_DEPTH != 15 && RASOPS_DEPTH != 24 && \
     34  1.1  rin     RASOPS_DEPTH != 32
     35  1.1  rin #error "Depth not supported"
     36  1.1  rin #endif
     37  1.1  rin 
     38  1.1  rin #if RASOPS_WIDTH != 8 && RASOPS_WIDTH != 12 && RASOPS_WIDTH != 16
     39  1.1  rin #error "Width not supported"
     40  1.1  rin #endif
     41  1.1  rin 
     42  1.1  rin #if   RASOPS_DEPTH == 8
     43  1.1  rin #define	FILLED_STAMP	15
     44  1.1  rin #elif RASOPS_DEPTH == 15
     45  1.1  rin #define	FILLED_STAMP	30
     46  1.1  rin #else
     47  1.1  rin #define	FILLED_STAMP	60
     48  1.1  rin #endif
     49  1.1  rin 
     50  1.1  rin #define	PUTCHAR_WIDTH1(depth, width)	rasops ## depth ## _putchar ## width
     51  1.1  rin #define	PUTCHAR_WIDTH(depth, width)	PUTCHAR_WIDTH1(depth, width)
     52  1.1  rin 
     53  1.1  rin #define	PUTCHAR1(depth)			rasops ## depth ## _putchar
     54  1.1  rin #define	PUTCHAR(depth)			PUTCHAR1(depth)
     55  1.1  rin 
     56  1.1  rin #define	MAKESTAMP1(depth)		rasops ## depth ## _makestamp
     57  1.1  rin #define	MAKESTAMP(depth)		MAKESTAMP1(depth)
     58  1.1  rin 
     59  1.1  rin /* ################################################################### */
     60  1.1  rin 
     61  1.1  rin #if RASOPS_DEPTH == 8
     62  1.1  rin 
     63  1.1  rin #define	SUBST_STAMP1(p, off)						\
     64  1.1  rin 	(p)[(off) * 1 + 0] =
     65  1.1  rin 
     66  1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
     67  1.1  rin 	do {								\
     68  1.1  rin 		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
     69  1.1  rin 		rp[(off) * 1 + 0] = STAMP_READ(so);			\
     70  1.1  rin 		if (ri->ri_hwbits) {					\
     71  1.1  rin 			hrp[(off) * 1 + 0] = STAMP_READ(so);		\
     72  1.1  rin 		}							\
     73  1.1  rin 	} while (0 /* CONSTCOND */);
     74  1.1  rin 
     75  1.1  rin #endif /* RASOPS_DEPTH == 8 */
     76  1.1  rin 
     77  1.1  rin /* ################################################################### */
     78  1.1  rin 
     79  1.1  rin #if RASOPS_DEPTH == 15
     80  1.1  rin 
     81  1.1  rin #define	SUBST_STAMP1(p, off)						\
     82  1.1  rin 	(p)[(off) * 2 + 0] = (p)[(off) * 2 + 1] =
     83  1.1  rin 
     84  1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
     85  1.1  rin 	do {								\
     86  1.1  rin 		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
     87  1.1  rin 		rp[(off) * 2 + 0] = STAMP_READ(so);			\
     88  1.1  rin 		rp[(off) * 2 + 1] = STAMP_READ(so +  4);		\
     89  1.1  rin 		if (ri->ri_hwbits) {					\
     90  1.1  rin 			hrp[(off) * 2 + 0] = STAMP_READ(so);		\
     91  1.1  rin 			hrp[(off) * 2 + 1] = STAMP_READ(so +  4);	\
     92  1.1  rin 		}							\
     93  1.1  rin 	} while (0 /* CONSTCOND */);
     94  1.1  rin 
     95  1.1  rin #endif /* RASOPS_DEPTH == 15 */
     96  1.1  rin 
     97  1.1  rin /* ################################################################### */
     98  1.1  rin 
     99  1.1  rin #if RASOPS_DEPTH == 24
    100  1.1  rin 
    101  1.1  rin #define	SUBST_STAMP1(p, off)						\
    102  1.1  rin 	(p)[(off) * 3 + 0] = (p)[(off) * 3 + 1] = (p)[(off) * 3 + 2] =
    103  1.1  rin 
    104  1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
    105  1.1  rin 	do {								\
    106  1.1  rin 		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
    107  1.1  rin 		rp[(off) * 3 + 0] = STAMP_READ(so);			\
    108  1.1  rin 		rp[(off) * 3 + 1] = STAMP_READ(so +  4);		\
    109  1.1  rin 		rp[(off) * 3 + 2] = STAMP_READ(so +  8);		\
    110  1.1  rin 		if (ri->ri_hwbits) {					\
    111  1.1  rin 			hrp[(off) * 3 + 0] = STAMP_READ(so);		\
    112  1.1  rin 			hrp[(off) * 3 + 1] = STAMP_READ(so +  4);	\
    113  1.1  rin 			hrp[(off) * 3 + 2] = STAMP_READ(so +  8);	\
    114  1.1  rin 		}							\
    115  1.1  rin 	} while (0 /* CONSTCOND */);
    116  1.1  rin 
    117  1.1  rin #endif /* RASOPS_DEPTH == 24 */
    118  1.1  rin 
    119  1.1  rin /* ################################################################### */
    120  1.1  rin 
    121  1.1  rin #if RASOPS_DEPTH == 32
    122  1.1  rin 
    123  1.1  rin #define	SUBST_STAMP1(p, off)						\
    124  1.1  rin 	(p)[(off) * 4 + 0] = (p)[(off) * 4 + 1] =			\
    125  1.1  rin 	(p)[(off) * 4 + 2] = (p)[(off) * 4 + 3] =
    126  1.1  rin 
    127  1.1  rin #define	SUBST_GLYPH1(index, nibble, off)				\
    128  1.1  rin 	do {								\
    129  1.1  rin 		so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK;	\
    130  1.1  rin 		rp[(off) * 4 + 0] = STAMP_READ(so);			\
    131  1.1  rin 		rp[(off) * 4 + 1] = STAMP_READ(so +  4);		\
    132  1.1  rin 		rp[(off) * 4 + 2] = STAMP_READ(so +  8);		\
    133  1.1  rin 		rp[(off) * 4 + 3] = STAMP_READ(so + 12);		\
    134  1.1  rin 		if (ri->ri_hwbits) {					\
    135  1.1  rin 			hrp[(off) * 4 + 0] = STAMP_READ(so);		\
    136  1.1  rin 			hrp[(off) * 4 + 1] = STAMP_READ(so +  4);	\
    137  1.1  rin 			hrp[(off) * 4 + 2] = STAMP_READ(so +  8);	\
    138  1.1  rin 			hrp[(off) * 4 + 3] = STAMP_READ(so + 12);	\
    139  1.1  rin 		}							\
    140  1.1  rin 	} while (0 /* CONSTCOND */);
    141  1.1  rin 
    142  1.1  rin #endif /* RASOPS_DEPTH == 32 */
    143  1.1  rin 
    144  1.1  rin /* ################################################################### */
    145  1.1  rin 
    146  1.1  rin #if   RASOPS_WIDTH == 8
    147  1.1  rin #define	SUBST_STAMP(p, val) \
    148  1.1  rin 	SUBST_STAMP1(p, 0) SUBST_STAMP1(p, 1) (val)
    149  1.1  rin #elif RASOPS_WIDTH == 12
    150  1.1  rin #define	SUBST_STAMP(p, val) \
    151  1.1  rin 	SUBST_STAMP1(p, 0) SUBST_STAMP1(p, 1) SUBST_STAMP1(p, 2) (val)
    152  1.1  rin #elif RASOPS_WIDTH == 16
    153  1.1  rin #define	SUBST_STAMP(p, val) \
    154  1.1  rin 	SUBST_STAMP1(p, 0) SUBST_STAMP1(p, 1) SUBST_STAMP1(p, 2) \
    155  1.1  rin 	SUBST_STAMP1(p, 3) (val)
    156  1.1  rin #endif
    157  1.1  rin 
    158  1.1  rin #if   RASOPS_WIDTH == 8
    159  1.1  rin #define	SUBST_GLYPH \
    160  1.1  rin 	SUBST_GLYPH1(0, 1, 0) SUBST_GLYPH1(0, 0, 1)
    161  1.1  rin #elif RASOPS_WIDTH == 12
    162  1.1  rin #define	SUBST_GLYPH \
    163  1.1  rin 	SUBST_GLYPH1(0, 1, 0) SUBST_GLYPH1(0, 0, 1) SUBST_GLYPH1(1, 1, 2)
    164  1.1  rin #elif RASOPS_WIDTH == 16
    165  1.1  rin #define	SUBST_GLYPH \
    166  1.1  rin 	SUBST_GLYPH1(0, 1, 0) SUBST_GLYPH1(0, 0, 1) SUBST_GLYPH1(1, 1, 2) \
    167  1.1  rin 	SUBST_GLYPH1(1, 0, 3)
    168  1.1  rin #endif
    169  1.1  rin 
    170  1.1  rin /*
    171  1.1  rin  * Width-optimized putchar function.
    172  1.1  rin  */
    173  1.1  rin static void
    174  1.1  rin PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH)(void *cookie, int row, int col,
    175  1.1  rin     u_int uc, long attr)
    176  1.1  rin {
    177  1.1  rin 	struct rasops_info *ri = (struct rasops_info *)cookie;
    178  1.1  rin 	struct wsdisplay_font *font = PICK_FONT(ri, uc);
    179  1.1  rin 	int height, so, fs;
    180  1.1  rin 	uint32_t *rp, *hrp = NULL;
    181  1.1  rin 	uint8_t *fr;
    182  1.1  rin 
    183  1.1  rin 	hrp = NULL; /* XXX GCC */
    184  1.1  rin 
    185  1.1  rin #ifdef RASOPS_CLIPPING
    186  1.1  rin 	/* Catches 'row < 0' case too */
    187  1.1  rin 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    188  1.1  rin 		return;
    189  1.1  rin 
    190  1.1  rin 	if ((unsigned)col >= (unsigned)ri->ri_cols)
    191  1.1  rin 		return;
    192  1.1  rin #endif
    193  1.1  rin 
    194  1.1  rin 	/* check if character fits into font limits */
    195  1.1  rin 	if (!CHAR_IN_FONT(uc, font))
    196  1.1  rin 		return;
    197  1.1  rin 
    198  1.1  rin 	/* Can't risk remaking the stamp if it's already in use */
    199  1.1  rin 	if (stamp_mutex++) {
    200  1.1  rin 		stamp_mutex--;
    201  1.1  rin 		PUTCHAR(RASOPS_DEPTH)(cookie, row, col, uc, attr);
    202  1.1  rin 		return;
    203  1.1  rin 	}
    204  1.1  rin 
    205  1.1  rin 	/* Recompute stamp? */
    206  1.1  rin 	if (attr != stamp_attr)
    207  1.1  rin 		MAKESTAMP(RASOPS_DEPTH)(ri, attr);
    208  1.1  rin 
    209  1.1  rin 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
    210  1.1  rin 	if (ri->ri_hwbits)
    211  1.1  rin 		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
    212  1.1  rin 		    col*ri->ri_xscale);
    213  1.1  rin 
    214  1.1  rin 	height = font->fontheight;
    215  1.1  rin 
    216  1.2  rin #if RASOPS_DEPTH != 24 /* XXXRO fix me! */
    217  1.1  rin 	if (uc == ' ') {
    218  1.1  rin 		while (height--) {
    219  1.1  rin 			SUBST_STAMP(rp, stamp[0]);
    220  1.1  rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    221  1.1  rin 			if (ri->ri_hwbits) {
    222  1.1  rin 				SUBST_STAMP(hrp, stamp[0]);
    223  1.1  rin 				DELTA(hrp, ri->ri_stride, uint32_t *);
    224  1.1  rin 			}
    225  1.1  rin 		}
    226  1.2  rin 	} else
    227  1.2  rin #endif
    228  1.2  rin 	{
    229  1.1  rin 		fr = FONT_GLYPH(uc, font, ri);
    230  1.1  rin 		fs = font->stride;
    231  1.1  rin 
    232  1.1  rin 		while (height--) {
    233  1.1  rin 			SUBST_GLYPH
    234  1.1  rin 
    235  1.1  rin 			fr += fs;
    236  1.1  rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    237  1.1  rin 			if (ri->ri_hwbits)
    238  1.1  rin 				DELTA(hrp, ri->ri_stride, uint32_t *);
    239  1.1  rin 		}
    240  1.1  rin 	}
    241  1.1  rin 
    242  1.1  rin 	/* Do underline */
    243  1.1  rin 	if ((attr & WSATTR_UNDERLINE) != 0) {
    244  1.1  rin 		DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
    245  1.1  rin 		SUBST_STAMP(rp, stamp[FILLED_STAMP]);
    246  1.1  rin 		if (ri->ri_hwbits)
    247  1.3  rin 			DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
    248  1.1  rin 			SUBST_STAMP(hrp, stamp[FILLED_STAMP]);
    249  1.1  rin 	}
    250  1.1  rin 
    251  1.1  rin 	stamp_mutex--;
    252  1.1  rin }
    253  1.1  rin 
    254  1.1  rin #undef	FILLED_STAMP
    255  1.1  rin 
    256  1.1  rin #undef	PUTCHAR_WIDTH1
    257  1.1  rin #undef	PUTCHAR_WIDTH
    258  1.1  rin 
    259  1.1  rin #undef	PUTCHAR1
    260  1.1  rin #undef	PUTCHAR
    261  1.1  rin 
    262  1.1  rin #undef	MAKESTAMP1
    263  1.1  rin #undef	MAKESTAMP
    264  1.1  rin 
    265  1.1  rin #undef	SUBST_STAMP1
    266  1.1  rin #undef	SUBST_STAMP
    267  1.1  rin 
    268  1.1  rin #undef	SUBST_GLYPH1
    269  1.1  rin #undef	SUBST_GLYPH
    270