2 * linux/drivers/video/cfb24.c -- Low level frame buffer operations for 24 bpp
3 * truecolor packed pixels
5 * Created 7 Mar 1998 by Geert Uytterhoeven
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
12 #include <linux/module.h>
13 #include <linux/tty.h>
14 #include <linux/console.h>
15 #include <linux/string.h>
18 #include <video/fbcon.h>
19 #include <video/fbcon-cfb24.h>
23 * 24 bpp packed pixels
26 void fbcon_cfb24_setup(struct display
*p
)
28 p
->next_line
= p
->line_length
? p
->line_length
: p
->var
.xres_virtual
*3;
32 void fbcon_cfb24_bmove(struct display
*p
, int sy
, int sx
, int dy
, int dx
,
33 int height
, int width
)
35 int bytes
= p
->next_line
, linesize
= bytes
* fontheight(p
), rows
;
38 if (sx
== 0 && dx
== 0 && width
* fontwidth(p
) * 3 == bytes
) {
39 mymemmove(p
->screen_base
+ dy
* linesize
,
40 p
->screen_base
+ sy
* linesize
,
44 if (fontwidthlog(p
)) {
45 sx
<<= fontwidthlog(p
);
46 dx
<<= fontwidthlog(p
);
47 width
<<= fontwidthlog(p
);
51 width
*= fontwidth(p
);
53 sx
*= 3; dx
*= 3; width
*= 3;
54 if (dy
< sy
|| (dy
== sy
&& dx
< sx
)) {
55 src
= p
->screen_base
+ sy
* linesize
+ sx
;
56 dst
= p
->screen_base
+ dy
* linesize
+ dx
;
57 for (rows
= height
* fontheight(p
); rows
--;) {
58 mymemmove(dst
, src
, width
);
63 src
= p
->screen_base
+ (sy
+height
) * linesize
+ sx
- bytes
;
64 dst
= p
->screen_base
+ (dy
+height
) * linesize
+ dx
- bytes
;
65 for (rows
= height
* fontheight(p
); rows
--;) {
66 mymemmove(dst
, src
, width
);
73 #if defined(__BIG_ENDIAN)
74 #define convert4to3(in1, in2, in3, in4, out1, out2, out3) \
76 out1 = (in1<<8) | (in2>>16); \
77 out2 = (in2<<16) | (in3>>8); \
78 out3 = (in3<<24) | in4; \
80 #elif defined(__LITTLE_ENDIAN)
81 #define convert4to3(in1, in2, in3, in4, out1, out2, out3) \
83 out1 = in1 | (in2<<24); \
84 out2 = (in2>> 8) | (in3<<16); \
85 out3 = (in3>>16) | (in4<< 8); \
88 #error FIXME: No endianness??
91 static inline void store4pixels(u32 d1
, u32 d2
, u32 d3
, u32 d4
, u32
*dest
)
93 convert4to3(d1
, d2
, d3
, d4
, *dest
++, *dest
++, *dest
++);
96 static inline void rectfill(u8
*dest
, int width
, int height
, u32 data
,
102 convert4to3(data
, data
, data
, data
, d1
, d2
, d3
);
103 while (height
-- > 0) {
104 u32
*p
= (u32
*)dest
;
105 for (i
= 0; i
< width
/4; i
++) {
114 void fbcon_cfb24_clear(struct vc_data
*conp
, struct display
*p
, int sy
, int sx
,
115 int height
, int width
)
118 int bytes
= p
->next_line
, lines
= height
* fontheight(p
);
121 dest
= p
->screen_base
+ sy
* fontheight(p
) * bytes
+ sx
* fontwidth(p
) * 3;
123 bgx
= ((u32
*)p
->dispsw_data
)[attr_bgcol_ec(p
, conp
)];
125 width
*= fontwidth(p
)/4;
126 if (width
* 12 == bytes
)
127 rectfill(dest
, lines
* width
* 4, 1, bgx
, bytes
);
129 rectfill(dest
, width
* 4, lines
, bgx
, bytes
);
132 void fbcon_cfb24_putc(struct vc_data
*conp
, struct display
*p
, int c
, int yy
,
135 u8
*dest
, *cdat
, bits
;
136 int bytes
= p
->next_line
, rows
;
137 u32 eorx
, fgx
, bgx
, d1
, d2
, d3
, d4
;
139 dest
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* fontwidth(p
) * 3;
140 if (fontwidth(p
) <= 8)
141 cdat
= p
->fontdata
+ (c
& p
->charmask
) * fontheight(p
);
143 cdat
= p
->fontdata
+ ((c
& p
->charmask
) * fontheight(p
) << 1);
145 fgx
= ((u32
*)p
->dispsw_data
)[attr_fgcol(p
, c
)];
146 bgx
= ((u32
*)p
->dispsw_data
)[attr_bgcol(p
, c
)];
149 for (rows
= fontheight(p
); rows
--; dest
+= bytes
) {
151 d1
= (-(bits
>> 7) & eorx
) ^ bgx
;
152 d2
= (-(bits
>> 6 & 1) & eorx
) ^ bgx
;
153 d3
= (-(bits
>> 5 & 1) & eorx
) ^ bgx
;
154 d4
= (-(bits
>> 4 & 1) & eorx
) ^ bgx
;
155 store4pixels(d1
, d2
, d3
, d4
, (u32
*)dest
);
156 if (fontwidth(p
) < 8)
158 d1
= (-(bits
>> 3 & 1) & eorx
) ^ bgx
;
159 d2
= (-(bits
>> 2 & 1) & eorx
) ^ bgx
;
160 d3
= (-(bits
>> 1 & 1) & eorx
) ^ bgx
;
161 d4
= (-(bits
& 1) & eorx
) ^ bgx
;
162 store4pixels(d1
, d2
, d3
, d4
, (u32
*)(dest
+12));
163 if (fontwidth(p
) < 12)
166 d1
= (-(bits
>> 7) & eorx
) ^ bgx
;
167 d2
= (-(bits
>> 6 & 1) & eorx
) ^ bgx
;
168 d3
= (-(bits
>> 5 & 1) & eorx
) ^ bgx
;
169 d4
= (-(bits
>> 4 & 1) & eorx
) ^ bgx
;
170 store4pixels(d1
, d2
, d3
, d4
, (u32
*)(dest
+24));
171 if (fontwidth(p
) < 16)
173 d1
= (-(bits
>> 3 & 1) & eorx
) ^ bgx
;
174 d2
= (-(bits
>> 2 & 1) & eorx
) ^ bgx
;
175 d3
= (-(bits
>> 1 & 1) & eorx
) ^ bgx
;
176 d4
= (-(bits
& 1) & eorx
) ^ bgx
;
177 store4pixels(d1
, d2
, d3
, d4
, (u32
*)(dest
+32));
181 void fbcon_cfb24_putcs(struct vc_data
*conp
, struct display
*p
,
182 const unsigned short *s
, int count
, int yy
, int xx
)
184 u8
*cdat
, *dest
, *dest0
, bits
;
186 int rows
, bytes
= p
->next_line
;
187 u32 eorx
, fgx
, bgx
, d1
, d2
, d3
, d4
;
189 dest0
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* fontwidth(p
) * 3;
190 fgx
= ((u32
*)p
->dispsw_data
)[attr_fgcol(p
, scr_readw(s
))];
191 bgx
= ((u32
*)p
->dispsw_data
)[attr_bgcol(p
, scr_readw(s
))];
194 c
= scr_readw(s
++) & p
->charmask
;
195 if (fontwidth(p
) <= 8)
196 cdat
= p
->fontdata
+ c
* fontheight(p
);
199 cdat
= p
->fontdata
+ (c
* fontheight(p
) << 1);
200 for (rows
= fontheight(p
), dest
= dest0
; rows
--; dest
+= bytes
) {
202 d1
= (-(bits
>> 7) & eorx
) ^ bgx
;
203 d2
= (-(bits
>> 6 & 1) & eorx
) ^ bgx
;
204 d3
= (-(bits
>> 5 & 1) & eorx
) ^ bgx
;
205 d4
= (-(bits
>> 4 & 1) & eorx
) ^ bgx
;
206 store4pixels(d1
, d2
, d3
, d4
, (u32
*)dest
);
207 if (fontwidth(p
) < 8)
209 d1
= (-(bits
>> 3 & 1) & eorx
) ^ bgx
;
210 d2
= (-(bits
>> 2 & 1) & eorx
) ^ bgx
;
211 d3
= (-(bits
>> 1 & 1) & eorx
) ^ bgx
;
212 d4
= (-(bits
& 1) & eorx
) ^ bgx
;
213 store4pixels(d1
, d2
, d3
, d4
, (u32
*)(dest
+12));
214 if (fontwidth(p
) < 12)
217 d1
= (-(bits
>> 7) & eorx
) ^ bgx
;
218 d2
= (-(bits
>> 6 & 1) & eorx
) ^ bgx
;
219 d3
= (-(bits
>> 5 & 1) & eorx
) ^ bgx
;
220 d4
= (-(bits
>> 4 & 1) & eorx
) ^ bgx
;
221 store4pixels(d1
, d2
, d3
, d4
, (u32
*)(dest
+24));
222 if (fontwidth(p
) < 16)
224 d1
= (-(bits
>> 3 & 1) & eorx
) ^ bgx
;
225 d2
= (-(bits
>> 2 & 1) & eorx
) ^ bgx
;
226 d3
= (-(bits
>> 1 & 1) & eorx
) ^ bgx
;
227 d4
= (-(bits
& 1) & eorx
) ^ bgx
;
228 store4pixels(d1
, d2
, d3
, d4
, (u32
*)(dest
+32));
230 dest0
+= fontwidth(p
)*3;
234 void fbcon_cfb24_revc(struct display
*p
, int xx
, int yy
)
237 int bytes
= p
->next_line
, rows
;
239 dest
= p
->screen_base
+ yy
* fontheight(p
) * bytes
+ xx
* fontwidth(p
) * 3;
240 for (rows
= fontheight(p
); rows
--; dest
+= bytes
) {
241 switch (fontwidth(p
)) {
243 ((u32
*)dest
)[9] ^= 0xffffffff; ((u32
*)dest
)[10] ^= 0xffffffff;
244 ((u32
*)dest
)[11] ^= 0xffffffff; /* FALL THROUGH */
246 ((u32
*)dest
)[6] ^= 0xffffffff; ((u32
*)dest
)[7] ^= 0xffffffff;
247 ((u32
*)dest
)[8] ^= 0xffffffff; /* FALL THROUGH */
249 ((u32
*)dest
)[3] ^= 0xffffffff; ((u32
*)dest
)[4] ^= 0xffffffff;
250 ((u32
*)dest
)[5] ^= 0xffffffff; /* FALL THROUGH */
252 ((u32
*)dest
)[0] ^= 0xffffffff; ((u32
*)dest
)[1] ^= 0xffffffff;
253 ((u32
*)dest
)[2] ^= 0xffffffff;
258 void fbcon_cfb24_clear_margins(struct vc_data
*conp
, struct display
*p
,
261 int bytes
= p
->next_line
;
264 unsigned int right_start
= conp
->vc_cols
*fontwidth(p
);
265 unsigned int bottom_start
= conp
->vc_rows
*fontheight(p
);
266 unsigned int right_width
, bottom_width
;
268 bgx
= ((u32
*)p
->dispsw_data
)[attr_bgcol_ec(p
, conp
)];
270 if (!bottom_only
&& (right_width
= p
->var
.xres
-right_start
))
271 rectfill(p
->screen_base
+right_start
*3, right_width
,
272 p
->var
.yres_virtual
, bgx
, bytes
);
273 if ((bottom_width
= p
->var
.yres
-bottom_start
))
274 rectfill(p
->screen_base
+(p
->var
.yoffset
+bottom_start
)*bytes
,
275 right_start
, bottom_width
, bgx
, bytes
);
280 * `switch' for the low level operations
283 struct display_switch fbcon_cfb24
= {
284 fbcon_cfb24_setup
, fbcon_cfb24_bmove
, fbcon_cfb24_clear
, fbcon_cfb24_putc
,
285 fbcon_cfb24_putcs
, fbcon_cfb24_revc
, NULL
, NULL
, fbcon_cfb24_clear_margins
,
286 FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
291 int init_module(void)
296 void cleanup_module(void)
302 * Visible symbols for modules
305 EXPORT_SYMBOL(fbcon_cfb24
);
306 EXPORT_SYMBOL(fbcon_cfb24_setup
);
307 EXPORT_SYMBOL(fbcon_cfb24_bmove
);
308 EXPORT_SYMBOL(fbcon_cfb24_clear
);
309 EXPORT_SYMBOL(fbcon_cfb24_putc
);
310 EXPORT_SYMBOL(fbcon_cfb24_putcs
);
311 EXPORT_SYMBOL(fbcon_cfb24_revc
);
312 EXPORT_SYMBOL(fbcon_cfb24_clear_margins
);