check out this series of posts by jasper st. pierre et al about how the x window system works, plus some 2d rasterisation techniques:
https://magcius.github.io/xplain/article/index.html
the figures are demos that use a tiny canvas-based x server they wrote in js!