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!

screenshot of x compositor demo, showing one translucent kitten window and one opaque kitten window, the latter of which is selected in their window “inspector”