rasops15.c revision 1.33 1 /* $NetBSD: rasops15.c,v 1.33 2019/07/31 02:04:14 rin Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.33 2019/07/31 02:04:14 rin Exp $");
34
35 #include "opt_rasops.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/time.h>
40
41 #include <dev/wscons/wsdisplayvar.h>
42 #include <dev/wscons/wsconsio.h>
43
44 #define _RASOPS_PRIVATE
45 #include <dev/rasops/rasops.h>
46
47 static void rasops15_putchar(void *, int, int, u_int, long);
48 static void rasops15_putchar_aa(void *, int, int, u_int, long);
49 #ifndef RASOPS_SMALL
50 static void rasops15_putchar8(void *, int, int, u_int, long);
51 static void rasops15_putchar12(void *, int, int, u_int, long);
52 static void rasops15_putchar16(void *, int, int, u_int, long);
53 static void rasops15_makestamp(struct rasops_info *, long);
54 #endif
55
56 #ifndef RASOPS_SMALL
57 /*
58 * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
59 * destination uint32_t[0] = STAMP_READ(offset)
60 * destination uint32_t[1] = STAMP_READ(offset + 4)
61 */
62 #define STAMP_SHIFT(fb, n) ((n) ? (fb) >> 1: (fb) << 3)
63 #define STAMP_MASK (0xf << 3)
64 #define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o)))
65 #endif
66
67 /*
68 * Initialize rasops_info struct for this colordepth.
69 */
70 void
71 rasops15_init(struct rasops_info *ri)
72 {
73
74 if (ri->ri_rnum == 0) {
75 ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
76 ri->ri_gnum += (ri->ri_depth == 16);
77
78 ri->ri_rpos = 10 + (ri->ri_depth == 16);
79 ri->ri_gpos = 5;
80 ri->ri_bpos = 0;
81 }
82
83 if (FONT_IS_ALPHA(ri->ri_font)) {
84 ri->ri_ops.putchar = rasops15_putchar_aa;
85 return;
86 }
87
88 switch (ri->ri_font->fontwidth) {
89 #ifndef RASOPS_SMALL
90 case 8:
91 ri->ri_ops.putchar = rasops15_putchar8;
92 break;
93 case 12:
94 ri->ri_ops.putchar = rasops15_putchar12;
95 break;
96 case 16:
97 ri->ri_ops.putchar = rasops15_putchar16;
98 break;
99 #endif /* !RASOPS_SMALL */
100 default:
101 ri->ri_ops.putchar = rasops15_putchar;
102 return;
103 }
104
105 #ifndef RASOPS_SMALL
106 rasops_allocstamp(ri, sizeof(uint32_t) * 32);
107 #endif
108 }
109
110 #define RASOPS_DEPTH 15
111 #include "rasops_putchar.h"
112 #include "rasops_putchar_aa.h"
113
114 #ifndef RASOPS_SMALL
115 /*
116 * Recompute the 4x1 blitting stamp.
117 */
118 static void
119 rasops15_makestamp(struct rasops_info *ri, long attr)
120 {
121 uint32_t *stamp = (uint32_t *)ri->ri_stamp;
122 uint32_t fg, bg;
123 int i;
124
125 fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffff;
126 bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffff;
127 ri->ri_stamp_attr = attr;
128
129 for (i = 0; i < 32; i += 2) {
130 #if BYTE_ORDER == LITTLE_ENDIAN
131 stamp[i] = (i & 16 ? fg : bg);
132 stamp[i] |= (i & 8 ? fg : bg) << 16;
133 stamp[i + 1] = (i & 4 ? fg : bg);
134 stamp[i + 1] |= (i & 2 ? fg : bg) << 16;
135 #else
136 stamp[i] = (i & 8 ? fg : bg);
137 stamp[i] |= (i & 16 ? fg : bg) << 16;
138 stamp[i + 1] = (i & 2 ? fg : bg);
139 stamp[i + 1] |= (i & 4 ? fg : bg) << 16;
140 #endif
141 }
142 }
143
144 #define RASOPS_WIDTH 8
145 #include "rasops_putchar_width.h"
146 #undef RASOPS_WIDTH
147
148 #define RASOPS_WIDTH 12
149 #include "rasops_putchar_width.h"
150 #undef RASOPS_WIDTH
151
152 #define RASOPS_WIDTH 16
153 #include "rasops_putchar_width.h"
154 #undef RASOPS_WIDTH
155
156 #endif /* !RASOPS_SMALL */
157