Explore glyphy for glyph rendering
https://github.com/behdad/glyphy/
Glyphy computes a kind of signed distance field for the curves of a glyph, and stores the resulting data in a texture atlas. It provides glsl helpers to incorporate into a shader that can render glyphs with that data.
Together with the new hb-draw api, this will let us avoid cairo and freetype for glyph rendering.
One advantage of the sdf approach is that the cached glyphs are size-independent, so we don't need to cache a separate sdf for each size.
We'll still need a traditional glyph cache, for Emoji and similar bitmaps.
For a first cut at integrating this, we probably want to copy much of what the glyphy demo does:
- Add a separate cache for sdf-encoded glyphs. Initially, I would just copy the simple "64-wide column" approach of the glyphy-demo cache
- Add a shader that can draw these encoded glyphs, copying much of the glyphy-demo shader
- Make gsk_gl_render_job_visit_text_node use the current code if it is dealing with color glyphs, and use the new cache+shader otherwise
In more detail:
It has its glyph cache here: https://github.com/behdad/glyphy/blob/master/demo/demo-atlas.cc
The code to encode and upload a glyph to the cache is here: https://github.com/behdad/glyphy/blob/master/demo/demo-font.cc#L210
The shader for using the encoded glyphs is here: https://github.com/behdad/glyphy/blob/master/demo/demo-fshader.glsl
It is using some glsl functions from here: https://github.com/behdad/glyphy/blob/master/src/glyphy-sdf.glsl
The code for using hb-draw api to get the curves out of a font is here: https://github.com/behdad/glyphy/blob/harfbuzz/src/glyphy-harfbuzz.h#L109
The hb-draw api itself is here: https://github.com/harfbuzz/harfbuzz/blob/main/src/hb-draw.h