Skip to content

Commit 86973f0

Browse files
committed
use hardware to draw anti-aliased characters
1 parent b5c5894 commit 86973f0

1 file changed

Lines changed: 111 additions & 32 deletions

File tree

sys/arch/hppa/dev/summitfb.c

Lines changed: 111 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: summitfb.c,v 1.29 2025/01/26 11:21:21 macallan Exp $ */
1+
/* $NetBSD: summitfb.c,v 1.30 2025/01/27 12:10:19 macallan Exp $ */
22

33
/* $OpenBSD: sti_pci.c,v 1.7 2009/02/06 22:51:04 miod Exp $ */
44

@@ -27,7 +27,7 @@
2727
*/
2828

2929
#include <sys/cdefs.h>
30-
__KERNEL_RCSID(0, "$NetBSD: summitfb.c,v 1.29 2025/01/26 11:21:21 macallan Exp $");
30+
__KERNEL_RCSID(0, "$NetBSD: summitfb.c,v 1.30 2025/01/27 12:10:19 macallan Exp $");
3131

3232
#include <sys/param.h>
3333
#include <sys/systm.h>
@@ -92,9 +92,8 @@ struct summitfb_softc {
9292
struct wsdisplay_font *sc_font;
9393
int sc_font_start; /* x of font area */
9494
int sc_cols; /* chars per line in font area */
95-
95+
uint32_t sc_palette[16];
9696
int sc_video_on;
97-
void (*sc_putchar)(void *, int, int, u_int, long);
9897
glyphcache sc_gc;
9998
};
10099

@@ -212,6 +211,26 @@ summitfb_write4(struct summitfb_softc *sc, uint32_t offset, uint32_t val)
212211
bus_space_write_stream_4(memt, memh, offset - 0x400000, val);
213212
}
214213

214+
static inline void
215+
summitfb_write_mode(struct summitfb_softc *sc, uint32_t mode)
216+
{
217+
if (sc->sc_write_mode == mode)
218+
return;
219+
summitfb_wait(sc);
220+
summitfb_write4(sc, VISFX_VRAM_WRITE_MODE, mode);
221+
sc->sc_write_mode = mode;
222+
}
223+
224+
static inline void
225+
summitfb_read_mode(struct summitfb_softc *sc, uint32_t mode)
226+
{
227+
if (sc->sc_read_mode == mode)
228+
return;
229+
summitfb_wait(sc);
230+
summitfb_write4(sc, VISFX_VRAM_READ_MODE, mode);
231+
sc->sc_read_mode = mode;
232+
}
233+
215234
void
216235
summitfb_attach(device_t parent, device_t self, void *aux)
217236
{
@@ -347,6 +366,37 @@ summitfb_attach(device_t parent, device_t self, void *aux)
347366
aa.accesscookie = &sc->vd;
348367

349368
config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARGS_NONE);
369+
#ifdef DEBUG
370+
{
371+
int i;
372+
373+
summitfb_rectfill(sc, 0, 824, 1280, 200, 0x00);
374+
summitfb_rectfill(sc, 5, 830, 100, 190, 0xe0); /* red */
375+
376+
summitfb_write_mode(sc, OTC01 | BIN332F | BUFovl);
377+
summitfb_read_mode(sc, OTC01 | BIN332F | BUFovl);
378+
summitfb_write4(sc, VISFX_CBR, 0x3f0000ff);
379+
summitfb_write4(sc, VISFX_FG_COLOUR, 0x7f00ff00);
380+
381+
for (i = 0; i < 16; i++) {
382+
summitfb_wait_fifo(sc, 10);
383+
summitfb_write4(sc, VISFX_IBO, 0x200 | (14 << 4) | i);
384+
summitfb_write4(sc, VISFX_COPY_SRC, (5 << 16) | 830);
385+
summitfb_write4(sc, VISFX_COPY_WH, (30 << 16) | 90);
386+
summitfb_write4(sc, VISFX_COPY_DST,
387+
((i * 35 + 200) << 16) | 830);
388+
}
389+
summitfb_write_mode(sc, OTC01 | BIN332F | BUFovl | 0x8c0);
390+
summitfb_write4(sc, VISFX_FG_COLOUR, 0x7f00ff00);
391+
for (i = 0; i < 16; i++) {
392+
summitfb_wait_fifo(sc, 10);
393+
summitfb_write4(sc, VISFX_IBO, 0x200 | (i << 4) | 5);
394+
summitfb_write4(sc, VISFX_START,
395+
((i * 35 + 200) << 16) | 930);
396+
summitfb_write4(sc, VISFX_SIZE, (30 << 16) | 90);
397+
}
398+
}
399+
#endif
350400
}
351401

352402
/*
@@ -648,26 +698,6 @@ summitfb_wait(struct summitfb_softc *sc)
648698
continue;
649699
}
650700

651-
static inline void
652-
summitfb_write_mode(struct summitfb_softc *sc, uint32_t mode)
653-
{
654-
if (sc->sc_write_mode == mode)
655-
return;
656-
summitfb_wait(sc);
657-
summitfb_write4(sc, VISFX_VRAM_WRITE_MODE, mode);
658-
sc->sc_write_mode = mode;
659-
}
660-
661-
static inline void
662-
summitfb_read_mode(struct summitfb_softc *sc, uint32_t mode)
663-
{
664-
if (sc->sc_read_mode == mode)
665-
return;
666-
summitfb_wait(sc);
667-
summitfb_write4(sc, VISFX_VRAM_READ_MODE, mode);
668-
sc->sc_read_mode = mode;
669-
}
670-
671701
static inline void
672702
summitfb_setup_fb(struct summitfb_softc *sc)
673703
{
@@ -677,12 +707,14 @@ summitfb_setup_fb(struct summitfb_softc *sc)
677707
summitfb_write_mode(sc, VISFX_WRITE_MODE_PLAIN);
678708
summitfb_read_mode(sc, VISFX_WRITE_MODE_PLAIN);
679709
summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_8);
680-
summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0); // opaque
710+
/* make overlay opaque */
711+
summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0);
681712
} else {
682713
summitfb_write_mode(sc, OTC01 | BIN8F | BUFFL);
683714
summitfb_read_mode(sc, OTC01 | BIN8F | BUFFL);
684715
summitfb_write4(sc, VISFX_APERTURE_ACCESS, VISFX_DEPTH_32);
685-
summitfb_write4(sc, VISFX_OTR, OTR_A); // all transparent
716+
/* make overlay transparent */
717+
summitfb_write4(sc, VISFX_OTR, OTR_A);
686718
}
687719
summitfb_write4(sc, VISFX_IBO, RopSrc);
688720
}
@@ -727,7 +759,8 @@ summitfb_setup(struct summitfb_softc *sc)
727759
((sc->sc_scr.fbwidth) << 16) | (sc->sc_scr.fbheight));
728760
/* turn off the cursor sprite */
729761
summitfb_write4(sc, VISFX_CURSOR_POS, 0);
730-
summitfb_write4(sc, VISFX_TCR, 0x10001000); /* disable throttling */
762+
/* disable throttling by moving the throttle window way off screen */
763+
summitfb_write4(sc, VISFX_TCR, 0x10001000);
731764

732765
/* make sure the overlay is opaque */
733766
summitfb_write4(sc, VISFX_OTR, OTR_T | OTR_L1 | OTR_L0);
@@ -948,7 +981,6 @@ summitfb_init_screen(void *cookie, struct vcons_screen *scr,
948981
ri->ri_ops.eraserows = summitfb_eraserows;
949982
ri->ri_ops.erasecols = summitfb_erasecols;
950983
ri->ri_ops.cursor = summitfb_cursor;
951-
sc->sc_putchar = ri->ri_ops.putchar;
952984
sc->sc_font = NULL;
953985
if (FONT_IS_ALPHA(ri->ri_font)) {
954986
ri->ri_ops.putchar = summitfb_putchar_aa;
@@ -1045,6 +1077,12 @@ summitfb_restore_palette(struct summitfb_softc *sc)
10451077
summitfb_putpalreg(sc, i, cmap[j], cmap[j + 1], cmap[j + 2]);
10461078
j += 3;
10471079
}
1080+
for (i = 0; i < 16; i++) {
1081+
sc->sc_palette[i] = (rasops_cmap[i * 3] << 16) |
1082+
(rasops_cmap[i * 3 + 1] << 8) |
1083+
rasops_cmap[i * 3 + 2];
1084+
}
1085+
10481086
}
10491087

10501088
static int
@@ -1345,8 +1383,9 @@ summitfb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
13451383
struct wsdisplay_font *font = PICK_FONT(ri, c);
13461384
struct vcons_screen *scr = ri->ri_hw;
13471385
struct summitfb_softc *sc = scr->scr_cookie;
1348-
int x, y, wi, he, rv = GC_NOPE;
1349-
uint32_t bg;
1386+
int x, y, wi, he, rv = GC_NOPE, i, j;
1387+
uint32_t bg, fg, tmp;
1388+
uint8_t *data;
13501389

13511390
if (sc->sc_mode != WSDISPLAYIO_MODE_EMUL)
13521391
return;
@@ -1375,9 +1414,49 @@ summitfb_putchar_aa(void *cookie, int row, int col, u_int c, long attr)
13751414
if (rv == GC_OK)
13761415
return;
13771416

1378-
summitfb_setup_fb(sc);
1379-
sc->sc_putchar(cookie, row, col, c, attr);
1417+
/*
1418+
* first we clear the background - we should be able to use the CBR
1419+
* register as constant background but so far I couldn't make that work
1420+
*/
1421+
summitfb_rectfill(sc, x, y, wi, he, bg);
1422+
1423+
/*
1424+
* if we ever figure out how to use a constant background colour we can
1425+
* skip the read mode setting
1426+
*/
1427+
summitfb_read_mode(sc, OTC01 | BIN332F | BUFovl);
1428+
summitfb_write_mode(sc, OTC01 | BIN332F | BUFovl);
1429+
/* we need the foreground colour as full RGB8 */
1430+
fg = sc->sc_palette[(attr >> 24) & 0xf];
13801431

1432+
/*
1433+
* set the blending equation to
1434+
* src_color * src_alpha + dst_color * (1 - src_alpha)
1435+
*/
1436+
summitfb_write4(sc, VISFX_IBO,
1437+
IBO_ADD | SRC(IBO_SRC) | DST(IBO_ONE_MINUS_SRC));
1438+
1439+
/* get the glyph */
1440+
data = WSFONT_GLYPH(c, font);
1441+
for (i = 0; i < he; i++) {
1442+
/*
1443+
* make some room in the pipeline
1444+
* with just plain ROPs we can just hammer the FIFO without
1445+
* having to worry about overflowing it but I suspect with
1446+
* alpha blending enabled things may be a little slower
1447+
*/
1448+
summitfb_wait_fifo(sc, wi * 2);
1449+
/* start a new line */
1450+
summitfb_write4(sc, VISFX_VRAM_WRITE_DEST, ((y + i) << 16) | x);
1451+
for (j = 0; j < wi; j++) {
1452+
tmp = *data;
1453+
/* alpha & RGB -> ARGB */
1454+
summitfb_write4(sc, VISFX_VRAM_WRITE_DATA_INCRX,
1455+
(tmp << 24) | fg);
1456+
data++;
1457+
}
1458+
}
1459+
13811460
if (rv == GC_ADD)
13821461
glyphcache_add(&sc->sc_gc, c, x, y);
13831462
}

0 commit comments

Comments
 (0)