gfx: one glyph blitter, and a terminal cell is a surface
Gate 0's last item, "delete the cell grid" -- done as far as it should be, and the rest of it retired, which is the part worth explaining. include/text.h made the case against the grid in four charges: it cannot do variable-width glyphs, cannot position text off a multiple of eight, cannot anti-alias, and cannot hold a codepoint above 255. Every one of those was about the *drawing layer*, and every one is now false -- glyphs carry metrics, PSOGM positions text at arbitrary pixels, the TrueType path blends 8-bit coverage, and vtcell.ch is a uint32. What is left is a grid in vt.c, and deleting that would not modernise the console; it would stop it being a terminal. VT100 escapes address columns, TIOCGWINSZ reports rows and columns, and every program that draws a box assumes both. So the item is checked with its remainder rewritten to say what was actually wrong, rather than ticked as if the original wording had been carried out. **What was actually wrong was the duplicate.** gfx.c walked font_data and blitted glyphs its own way; text.c did the same job into a struct surface, for no caller but a sysrq self-test. Two implementations of bearings, coverage and clipping, which had to agree about a cell size only one of them was told had changed -- and they did not agree, which is why every line of PSOGM once drew the next character's bitmap underneath itself. There is one now, and the mechanism is the pleasing part: the console hands text_draw_glyph() **the cell as a surface of its own** -- same pixels, same stride, origin moved and bounds set to that cell. Clipping a tall ascender to its line is then the same bounds check that clips to the edge of a screen, and there is no second notion of clipping in the tree. `surface_sub()` is six lines and replaced fourteen of hand-written comparisons. The bitmap is reached through font_builtin() like any other provider, so the early console and the real one are one path with different metrics, and the `if (!cfont)` branch that walked the array is gone. gfx.c no longer includes font.h; text.c does, being the only file left that reads it -- which also retires the note in text.c explaining why it could not. struct surface gained a bpp, because gfx_draw_pixel handles 16, 24 and 32 and whatever replaces it has to as well. Zero means 32: a UEFI GOP has no other format and the loader publishes 32 unconditionally, so callers that do not care say nothing. One behaviour change, and it is the documented one: a codepoint the font cannot draw is now a substituted glyph rather than a blank cell. text.h argues for that directly -- "a missing glyph that draws nothing makes text silently shorter and the fault impossible to see". Verified by screendump: the console renders correctly, PSOGM renders correctly, and `echo t > /proc/sysrq` still draws its specimen through the surface path with the back buffer at 32bpp. Both supported configurations: one boot each, no traps, no panics, socktest and memfdtest green. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
d85274dbd9
commit
c84d06c5b1
6 changed files with 183 additions and 72 deletions
|
|
@ -2,12 +2,18 @@
|
|||
|
||||
// Text rendering.
|
||||
//
|
||||
// The console draws text by indexing `font_data[256][16]` and stepping the
|
||||
// cursor eight pixels. That is a *character cell grid*, and it is the thing in
|
||||
// the way -- not the font. A grid cannot do variable-width glyphs, cannot
|
||||
// position text anywhere except on a multiple of eight, cannot anti-alias, and
|
||||
// cannot represent a codepoint above 255. Swapping the bitmap for a nicer
|
||||
// bitmap changes none of that.
|
||||
// The console used to draw text by indexing `font_data[256][16]` and stepping
|
||||
// the cursor eight pixels. That is a *character cell grid*, and it was the
|
||||
// thing in the way -- not the font. A grid like that cannot do variable-width
|
||||
// glyphs, cannot position text anywhere except on a multiple of eight, cannot
|
||||
// anti-alias, and cannot represent a codepoint above 255. Swapping the bitmap
|
||||
// for a nicer bitmap changed none of that.
|
||||
//
|
||||
// None of it is true any more, and the console draws through this file. What
|
||||
// remains a grid is `vt.c`'s model of a terminal, which is not the same claim:
|
||||
// a terminal *is* rows and columns -- VT100 escapes address them and
|
||||
// TIOCGWINSZ reports them -- and it reaches this renderer by handing it one
|
||||
// cell at a time, as a surface.
|
||||
//
|
||||
// So this is a layer, not a font. Three things it fixes:
|
||||
//
|
||||
|
|
@ -30,11 +36,25 @@ struct font;
|
|||
// same code has to work on the virtio-gpu back buffer, on a window's own
|
||||
// buffer, and on the VGA aperture, and none of those know about each other.
|
||||
struct surface {
|
||||
void *pixels; // 32-bit 0x00RRGGBB, the format everything here uses
|
||||
void *pixels; // 0x00RRGGBB, at `bpp` bits each
|
||||
uint32 stride; // bytes per row, not pixels -- they differ on real hardware
|
||||
int width, height;
|
||||
// 32 nearly always: a UEFI GOP has no other format and the loader publishes
|
||||
// 32 unconditionally. 24 and 16 are here because a framebuffer is allowed to
|
||||
// be either and a glyph drawn at the wrong depth is not a subtle failure.
|
||||
// Zero means 32, so a caller that does not care does not have to say.
|
||||
int bpp;
|
||||
};
|
||||
|
||||
// A rectangle of a surface, as a surface of its own.
|
||||
//
|
||||
// Which is how a terminal cell is expressed: everything that draws into it is
|
||||
// then clipped to it by the same bounds check that clips to a screen, with no
|
||||
// second notion of clipping anywhere. A glyph with a tall ascender cannot
|
||||
// bleed into the line above, because as far as the renderer is concerned the
|
||||
// line above is off the edge of the world.
|
||||
struct surface surface_sub(const struct surface *s, int x, int y, int w, int h);
|
||||
|
||||
// One rendered glyph. `cov` is 8-bit coverage, not a bitmap: 0 is background,
|
||||
// 255 is solid, and everything between is an anti-aliased edge. A bitmap font
|
||||
// fills it with 0 and 255 only, and costs nothing for the generality.
|
||||
|
|
|
|||
Loading…
Reference in a new issue