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