rasops_putchar_width.h revision 1.6 1 1.6 rin /* $NetBSD: rasops_putchar_width.h,v 1.6 2019/07/28 12:06:10 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.5 rin #define SUBST_STAMP1(p, off, base) \
64 1.5 rin (p)[(off) * 1 + 0] = stamp[base]
65 1.1 rin
66 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
67 1.1 rin do { \
68 1.6 rin int 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.5 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.5 rin #define SUBST_STAMP1(p, off, base) \
82 1.5 rin (p)[(off) * 2 + 0] = (p)[(off) * 2 + 1] = stamp[base]
83 1.1 rin
84 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
85 1.1 rin do { \
86 1.6 rin int 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.5 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.4 rin #define SUBST_STAMP1(p, off, base) \
102 1.4 rin do { \
103 1.4 rin (p)[(off) * 3 + 0] = stamp[(base) + 0]; \
104 1.4 rin (p)[(off) * 3 + 1] = stamp[(base) + 1]; \
105 1.4 rin (p)[(off) * 3 + 2] = stamp[(base) + 2]; \
106 1.5 rin } while (0 /* CONSTCOND */)
107 1.1 rin
108 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
109 1.1 rin do { \
110 1.6 rin int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \
111 1.1 rin rp[(off) * 3 + 0] = STAMP_READ(so); \
112 1.1 rin rp[(off) * 3 + 1] = STAMP_READ(so + 4); \
113 1.1 rin rp[(off) * 3 + 2] = STAMP_READ(so + 8); \
114 1.1 rin if (ri->ri_hwbits) { \
115 1.1 rin hrp[(off) * 3 + 0] = STAMP_READ(so); \
116 1.1 rin hrp[(off) * 3 + 1] = STAMP_READ(so + 4); \
117 1.1 rin hrp[(off) * 3 + 2] = STAMP_READ(so + 8); \
118 1.1 rin } \
119 1.5 rin } while (0 /* CONSTCOND */)
120 1.1 rin
121 1.1 rin #endif /* RASOPS_DEPTH == 24 */
122 1.1 rin
123 1.1 rin /* ################################################################### */
124 1.1 rin
125 1.1 rin #if RASOPS_DEPTH == 32
126 1.1 rin
127 1.5 rin #define SUBST_STAMP1(p, off, base) \
128 1.1 rin (p)[(off) * 4 + 0] = (p)[(off) * 4 + 1] = \
129 1.5 rin (p)[(off) * 4 + 2] = (p)[(off) * 4 + 3] = stamp[base]
130 1.1 rin
131 1.1 rin #define SUBST_GLYPH1(index, nibble, off) \
132 1.1 rin do { \
133 1.6 rin int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \
134 1.1 rin rp[(off) * 4 + 0] = STAMP_READ(so); \
135 1.1 rin rp[(off) * 4 + 1] = STAMP_READ(so + 4); \
136 1.1 rin rp[(off) * 4 + 2] = STAMP_READ(so + 8); \
137 1.1 rin rp[(off) * 4 + 3] = STAMP_READ(so + 12); \
138 1.1 rin if (ri->ri_hwbits) { \
139 1.1 rin hrp[(off) * 4 + 0] = STAMP_READ(so); \
140 1.1 rin hrp[(off) * 4 + 1] = STAMP_READ(so + 4); \
141 1.1 rin hrp[(off) * 4 + 2] = STAMP_READ(so + 8); \
142 1.1 rin hrp[(off) * 4 + 3] = STAMP_READ(so + 12); \
143 1.1 rin } \
144 1.5 rin } while (0 /* CONSTCOND */)
145 1.1 rin
146 1.1 rin #endif /* RASOPS_DEPTH == 32 */
147 1.1 rin
148 1.1 rin /* ################################################################### */
149 1.1 rin
150 1.4 rin #if RASOPS_WIDTH == 8
151 1.5 rin #define SUBST_STAMP(p, base) \
152 1.5 rin do { \
153 1.5 rin SUBST_STAMP1(p, 0, base); \
154 1.5 rin SUBST_STAMP1(p, 1, base); \
155 1.5 rin } while (0 /* CONSTCOND */)
156 1.4 rin #elif RASOPS_WIDTH == 12
157 1.5 rin #define SUBST_STAMP(p, base) \
158 1.5 rin do { \
159 1.5 rin SUBST_STAMP1(p, 0, base); \
160 1.5 rin SUBST_STAMP1(p, 1, base); \
161 1.5 rin SUBST_STAMP1(p, 2, base); \
162 1.5 rin } while (0 /* CONSTCOND */)
163 1.4 rin #elif RASOPS_WIDTH == 16
164 1.5 rin #define SUBST_STAMP(p, base) \
165 1.5 rin do { \
166 1.5 rin SUBST_STAMP1(p, 0, base); \
167 1.5 rin SUBST_STAMP1(p, 1, base); \
168 1.5 rin SUBST_STAMP1(p, 2, base); \
169 1.5 rin SUBST_STAMP1(p, 3, base); \
170 1.5 rin } while (0 /* CONSTCOND */)
171 1.4 rin #endif
172 1.1 rin
173 1.1 rin #if RASOPS_WIDTH == 8
174 1.5 rin #define SUBST_GLYPH \
175 1.5 rin do { \
176 1.5 rin SUBST_GLYPH1(0, 1, 0); \
177 1.5 rin SUBST_GLYPH1(0, 0, 1); \
178 1.5 rin } while (0 /* CONSTCOND */)
179 1.1 rin #elif RASOPS_WIDTH == 12
180 1.5 rin #define SUBST_GLYPH \
181 1.5 rin do { \
182 1.5 rin SUBST_GLYPH1(0, 1, 0); \
183 1.5 rin SUBST_GLYPH1(0, 0, 1); \
184 1.5 rin SUBST_GLYPH1(1, 1, 2); \
185 1.5 rin } while (0 /* CONSTCOND */)
186 1.1 rin #elif RASOPS_WIDTH == 16
187 1.5 rin #define SUBST_GLYPH \
188 1.5 rin do { \
189 1.5 rin SUBST_GLYPH1(0, 1, 0); \
190 1.5 rin SUBST_GLYPH1(0, 0, 1); \
191 1.5 rin SUBST_GLYPH1(1, 1, 2); \
192 1.5 rin SUBST_GLYPH1(1, 0, 3); \
193 1.5 rin } while (0 /* CONSTCOND */)
194 1.1 rin #endif
195 1.1 rin
196 1.1 rin /*
197 1.1 rin * Width-optimized putchar function.
198 1.1 rin */
199 1.1 rin static void
200 1.1 rin PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH)(void *cookie, int row, int col,
201 1.1 rin u_int uc, long attr)
202 1.1 rin {
203 1.1 rin struct rasops_info *ri = (struct rasops_info *)cookie;
204 1.1 rin struct wsdisplay_font *font = PICK_FONT(ri, uc);
205 1.6 rin int height, fs;
206 1.6 rin uint32_t *rp, *hrp;
207 1.1 rin uint8_t *fr;
208 1.1 rin
209 1.1 rin hrp = NULL; /* XXX GCC */
210 1.1 rin
211 1.1 rin #ifdef RASOPS_CLIPPING
212 1.1 rin /* Catches 'row < 0' case too */
213 1.1 rin if ((unsigned)row >= (unsigned)ri->ri_rows)
214 1.1 rin return;
215 1.1 rin
216 1.1 rin if ((unsigned)col >= (unsigned)ri->ri_cols)
217 1.1 rin return;
218 1.1 rin #endif
219 1.1 rin
220 1.1 rin /* check if character fits into font limits */
221 1.1 rin if (!CHAR_IN_FONT(uc, font))
222 1.1 rin return;
223 1.1 rin
224 1.1 rin /* Can't risk remaking the stamp if it's already in use */
225 1.1 rin if (stamp_mutex++) {
226 1.1 rin stamp_mutex--;
227 1.1 rin PUTCHAR(RASOPS_DEPTH)(cookie, row, col, uc, attr);
228 1.1 rin return;
229 1.1 rin }
230 1.1 rin
231 1.1 rin /* Recompute stamp? */
232 1.1 rin if (attr != stamp_attr)
233 1.1 rin MAKESTAMP(RASOPS_DEPTH)(ri, attr);
234 1.1 rin
235 1.1 rin rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
236 1.1 rin if (ri->ri_hwbits)
237 1.1 rin hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
238 1.1 rin col*ri->ri_xscale);
239 1.1 rin
240 1.1 rin height = font->fontheight;
241 1.1 rin
242 1.1 rin if (uc == ' ') {
243 1.1 rin while (height--) {
244 1.4 rin SUBST_STAMP(rp, 0);
245 1.1 rin DELTA(rp, ri->ri_stride, uint32_t *);
246 1.1 rin if (ri->ri_hwbits) {
247 1.4 rin SUBST_STAMP(hrp, 0);
248 1.1 rin DELTA(hrp, ri->ri_stride, uint32_t *);
249 1.1 rin }
250 1.1 rin }
251 1.4 rin } else {
252 1.1 rin fr = FONT_GLYPH(uc, font, ri);
253 1.1 rin fs = font->stride;
254 1.1 rin
255 1.1 rin while (height--) {
256 1.4 rin SUBST_GLYPH;
257 1.1 rin
258 1.1 rin fr += fs;
259 1.1 rin DELTA(rp, ri->ri_stride, uint32_t *);
260 1.1 rin if (ri->ri_hwbits)
261 1.1 rin DELTA(hrp, ri->ri_stride, uint32_t *);
262 1.1 rin }
263 1.1 rin }
264 1.1 rin
265 1.1 rin /* Do underline */
266 1.1 rin if ((attr & WSATTR_UNDERLINE) != 0) {
267 1.1 rin DELTA(rp, -(ri->ri_stride << 1), uint32_t *);
268 1.4 rin SUBST_STAMP(rp, FILLED_STAMP);
269 1.4 rin if (ri->ri_hwbits) {
270 1.3 rin DELTA(hrp, -(ri->ri_stride << 1), uint32_t *);
271 1.4 rin SUBST_STAMP(hrp, FILLED_STAMP);
272 1.4 rin }
273 1.1 rin }
274 1.1 rin
275 1.1 rin stamp_mutex--;
276 1.1 rin }
277 1.1 rin
278 1.1 rin #undef FILLED_STAMP
279 1.1 rin
280 1.1 rin #undef PUTCHAR_WIDTH1
281 1.1 rin #undef PUTCHAR_WIDTH
282 1.1 rin
283 1.1 rin #undef PUTCHAR1
284 1.1 rin #undef PUTCHAR
285 1.1 rin
286 1.1 rin #undef MAKESTAMP1
287 1.1 rin #undef MAKESTAMP
288 1.1 rin
289 1.1 rin #undef SUBST_STAMP1
290 1.1 rin #undef SUBST_STAMP
291 1.1 rin
292 1.1 rin #undef SUBST_GLYPH1
293 1.1 rin #undef SUBST_GLYPH
294