Skip to content

Commit f18e2c6

Browse files
committed
Use bitblit() to render TLFT fonts
And with this, fillmask() and fillstretchmask() can finally go away!
1 parent 0206c1e commit f18e2c6

File tree

9 files changed

+92
-343
lines changed

9 files changed

+92
-343
lines changed

kos/include/libvideo/gfx/buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ video_buffer_getgfx(struct video_buffer *__self,
571571
gfx_blendmode_t __blendmode);
572572
extern __ATTR_RETNONNULL __ATTR_INOUT(1) __ATTR_OUT(2) struct video_gfx *
573573
video_buffer_getgfx_ex(struct video_buffer *__self, struct video_gfx *__result,
574-
gfx_blendmode_t __blendmode, struct video_palette *__used_palette,
574+
gfx_blendmode_t __blendmode, struct video_palette const *__used_palette,
575575
video_gfx_flag_t __used_flags, video_pixel_t __used_colorkey);
576576

577577

kos/include/libvideo/gfx/font.h

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,35 +35,16 @@
3535

3636
#include "../color.h" /* video_color_t */
3737
#include "../types.h"
38-
#include "gfx-flags.h"
39-
40-
41-
#if 0 /* TODO */
42-
/* Possible values for `video_font_gfx_flag_t' */
43-
#define VIDEO_FONT_GFX_F_NORMAL 0x0000 /* Normal font GFX flags */
44-
#define VIDEO_FONT_GFX_F_FGONLY VIDEO_GFX_F_COLORKEY /* Only render foreground */
45-
#define VIDEO_FONT_GFX_F_LINEAR VIDEO_GFX_F_LINEAR /* Use linear interpolation when stretching non-vector glyphs */
46-
#endif
4738

4839
#ifdef __CC__
4940
__DECL_BEGIN
5041

51-
#if 0 /* TODO */
52-
/* Set of `VIDEO_FONT_GFX_F*' */
53-
typedef video_gfx_flag_t video_font_gfx_flag_t;
54-
#endif
55-
5642
struct video_gfx;
5743
struct video_font;
5844

5945
struct video_font_ops {
6046
/* All operators within this structure are [1..1] */
6147

62-
#if 0 /* TODO */
63-
__ATTR_NONNULL_T((1)) void
64-
(LIBVIDEO_GFX_CC *vfo_getgfx)(struct video_font *__restrict __self);
65-
#endif
66-
6748
/* Destroy the given video font object. */
6849
__ATTR_NONNULL_T((1)) void
6950
(LIBVIDEO_GFX_CC *vfo_destroy)(struct video_font *__restrict __self);
@@ -102,15 +83,9 @@ struct video_font_ops {
10283

10384

10485
struct video_font {
105-
#if 0 /* TODO */
106-
struct video_font_ops vf_ops; /* [1..1][const] Operators. */
107-
struct video_domain const *vf_domain; /* [1..1][const] Domain in which this font is opened. */
108-
__uintptr_t vf_refcnt; /* Reference counter. */
109-
/* Remainder of this structure contains type-specific data. */
110-
#else
111-
__uintptr_t vf_refcnt; /* Reference counter. */
112-
struct video_font_ops *vf_ops; /* [1..1] Operators. */
113-
#endif
86+
struct video_font_ops const *vf_ops; /* [1..1][const] Operators. */
87+
struct video_domain const *vf_domain; /* [1..1][const] Domain for which this font was allocated. */
88+
__uintptr_t vf_refcnt; /* Reference counter. */
11489
};
11590

11691
#define video_font_destroy(self) (*(self)->vf_ops->vfo_destroy)(self)
@@ -123,37 +98,17 @@ __DEFINE_REFCNT_FUNCTIONS(struct video_font, vf_refcnt, video_font_destroy)
12398

12499

125100

126-
#if 0 /* TODO */
127-
struct video_font_gfx {
128-
struct video_font const *vfx_font; /* [1..1][const] The font used for printing. */
129-
video_dim_t vfx_height; /* Glyph height. */
130-
video_color_t vfx_bg_fg[2]; /* Output colors for the next glyph. */
131-
void *_vfx_drv1[2]; /* ... (may be used internally) */
132-
video_font_gfx_flag_t vfx_flags; /* Set of `' */
133-
void *_vfx_drv2[2]; /* ... (may be used internally) */
134-
};
135-
#endif
136-
137-
138101
/* Lookup and return a reference to a video font, given its name.
139102
* @param: name: The font's name (the name of a file in `/lib/fonts/',
140103
* or an absolute path if it contains a `/'). Else, you
141104
* may also pass one of `VIDEO_FONT_*'
142105
* @return: NULL: [errno=ENOENT] Unknown font `name' */
143-
#if 0 /* TODO */
144106
typedef __ATTR_WUNUSED_T __ATTR_NONNULL_T((1)) __REF struct video_font *
145107
(LIBVIDEO_GFX_CC *PVIDEO_FONT_LOOKUP)(struct video_domain const *__restrict __domain, char const *__name);
146108
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
147109
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __ATTR_NONNULL((1)) __REF struct video_font *LIBVIDEO_GFX_CC
148110
video_font_lookup(struct video_domain const *__restrict __domain, char const *__name);
149111
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
150-
#else
151-
typedef __ATTR_WUNUSED_T __REF struct video_font *
152-
(LIBVIDEO_GFX_CC *PVIDEO_FONT_LOOKUP)(char const *__name);
153-
#ifdef LIBVIDEO_GFX_WANT_PROTOTYPES
154-
LIBVIDEO_GFX_DECL __ATTR_WUNUSED __REF struct video_font *LIBVIDEO_GFX_CC video_font_lookup(char const *__name);
155-
#endif /* LIBVIDEO_GFX_WANT_PROTOTYPES */
156-
#endif
157112

158113
/* Special font names. */
159114
#define VIDEO_FONT_DEFAULT (__CCAST(char const *)-1) /* Default system font. */

kos/src/apps/gfx/main.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,18 @@ int main(int argc, char *argv[]) {
9292

9393
enable_rawtty_mode();
9494

95-
/* Load the video-mode font. */
96-
font = video_font_lookup(VIDEO_FONT_FIXEDWIDTH);
97-
if (!font)
98-
err(EXIT_FAILURE, "Failed to load VIDEO_FONT_FIXEDWIDTH");
99-
10095
/* Bind the screen buffer. */
10196
screen = screen_buffer_create(NULL);
10297
if (!screen)
10398
err(EXIT_FAILURE, "Failed to load screen buffer");
10499
video_buffer_getgfx(screen, &gfx, GFX_BLENDMODE_ALPHA);
105100

101+
/* Load the video-mode font. */
102+
font = video_font_lookup(video_gfx_getdomain(&gfx),
103+
VIDEO_FONT_FIXEDWIDTH);
104+
if (!font)
105+
err(EXIT_FAILURE, "Failed to load VIDEO_FONT_FIXEDWIDTH");
106+
106107
fontprinter_data.vfp_height = 16;
107108
fontprinter_data.vfp_font = font;
108109
fontprinter_data.vfp_lnstart = 0;

kos/src/apps/showpic/main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,6 @@ int main(int argc, char *argv[]) {
552552
return 1;
553553
}
554554

555-
/* Load default system font */
556-
font = video_font_lookup(VIDEO_FONT_DEFAULT);
557-
558555
/* Bind the screen buffer. */
559556
screen = screen_buffer_create(NULL);
560557
if (!screen)
@@ -576,6 +573,10 @@ int main(int argc, char *argv[]) {
576573
bscreen = screen_buffer_asvideo(screen);
577574
#endif
578575

576+
/* Load default system font */
577+
font = video_font_lookup(video_buffer_getdomain(bscreen),
578+
VIDEO_FONT_DEFAULT);
579+
579580
#if 1
580581
{
581582
struct video_window_position position;

kos/src/libvideo/gfx/font.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@
5151

5252
DECL_BEGIN
5353

54-
PRIVATE WUNUSED REF struct video_font *CC
55-
libvideo_font_openfile(char const *filename) {
54+
PRIVATE WUNUSED NONNULL((1, 2)) REF struct video_font *CC
55+
libvideo_font_openfile(struct video_domain const *__restrict domain,
56+
char const *filename) {
5657
struct mapfile mf;
5758
REF struct video_font *result;
5859
/* Map the font file into memory. */
5960
if unlikely(mapfile(&mf, filename, 0, 0, (size_t)-1, 0, 0))
6061
goto err;
61-
result = libvideo_font_tryopen_tlft(&mf);
62+
result = libvideo_font_tryopen_tlft(domain, &mf);
6263
if (!result)
6364
goto err_unmap;
6465
if (result != (REF struct video_font *)-1)
@@ -74,8 +75,9 @@ libvideo_font_openfile(char const *filename) {
7475
}
7576

7677

77-
PRIVATE WUNUSED REF struct video_font *CC
78-
libvideo_font_create(char const *__restrict name) {
78+
PRIVATE WUNUSED NONNULL((1, 2)) REF struct video_font *CC
79+
libvideo_font_create(struct video_domain const *__restrict domain,
80+
char const *__restrict name) {
7981
char *full_name;
8082
if (strchr(name, '/')) {
8183
full_name = (char *)name;
@@ -90,7 +92,7 @@ libvideo_font_create(char const *__restrict name) {
9092
p = (char *)mempcpy(p, name, namelen * sizeof(char));
9193
*p = 0;
9294
}
93-
return libvideo_font_openfile(full_name);
95+
return libvideo_font_openfile(domain, full_name);
9496
}
9597

9698

@@ -100,8 +102,9 @@ libvideo_font_create(char const *__restrict name) {
100102
* or an absolute path if it contains a `/'). Else, you
101103
* may also pass one of `VIDEO_FONT_*'
102104
* @return: NULL: [errno=ENOENT] Unknown font `name' */
103-
INTERN WUNUSED REF struct video_font *CC
104-
libvideo_font_lookup(char const *name) {
105+
INTERN WUNUSED NONNULL((1)) REF struct video_font *CC
106+
libvideo_font_lookup(struct video_domain const *__restrict domain,
107+
char const *name) {
105108
REF struct video_font *result;
106109
if (VIDEO_FONT_ISPECIAL(name)) {
107110
if (name == VIDEO_FONT_DEFAULT ||
@@ -117,7 +120,7 @@ libvideo_font_lookup(char const *name) {
117120
return NULL;
118121
}
119122
}
120-
result = libvideo_font_create(name);
123+
result = libvideo_font_create(domain, name);
121124
assert(!result || result->vf_ops);
122125
assert(!result || result->vf_ops->vfo_destroy);
123126
assert(!result || result->vf_ops->vfo_drawglyph);

kos/src/libvideo/gfx/font.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ DECL_BEGIN
4444
* or an absolute path if it contains a `/'). Else, you
4545
* may also pass one of `VIDEO_FONT_*'
4646
* @return: NULL: [errno=ENOENT] Unknown font `name' */
47-
INTDEF WUNUSED __REF struct video_font *CC
48-
libvideo_font_lookup(char const *name);
47+
INTDEF WUNUSED NONNULL((1)) __REF struct video_font *CC
48+
libvideo_font_lookup(struct video_domain const *__restrict domain,
49+
char const *name);
4950

5051
/* Print text into a graphics context through use of this pformatprinter-compatible function. */
5152
INTDEF NONNULL((1, 2)) ssize_t FORMATPRINTER_CC

0 commit comments

Comments
 (0)