Back in my College days I had a course on computer graphics and how elements such as windows, buttons, input boxes, etc. etc. end up on the screen (both on the desktop and on mobile from today's perspective) and how they can overlap and disappear behind each other. But that's been some time ago so I was quite glad to have stumbled over a quick refresher on the difference of X and Wayland here. The first part of the post is quite easily understandable for those with a general background of how a desktop is rendered while the second part is quite a deep dive. But even if you don't want to go down that deep the post is still worth reading.
P.S.: And no I don't want to get into the debate of Wayland vs. Mir.