glamor: imprecise rendering of X primitives like lines and rectangles
Cases of interest:
-
xterm -uc
uses XDrawLines to draw the underline cursor; effectively produces a rectangle. -
xterm +uc
appears to be using XDrawRectangle directly (if xterm has focus, that rectangle will be filled, but the interesting case is when focus is away and the rectangle is not filled)
The lower right corner of the cursor is missing a pixel.
Deactivating the glamor module in Xorg server fixes the issue. The following testcase approximately does the same as glamor, and one can observe the very same problem that a corner of the 1-pixel thick box is missing.
By drawing the box with a larger line width, one can observe that the reason has to do with line cap styles. Apparently, the GL default is butt cap style. Such a line begins and ends in the middle of a pixel, which means that rounding is a concern and explains the way corners look. Switching to a square cap style would help.
Then I realized X was not necessarily designed for bitmap-only output, so butt cap style does make sense after all. But then, it's implemented wrong in my opinion. If you draw a rectangle as a line strip in e.g. Inkscape, the joints are proper even with butt cap style; what GL is doing is draw each segment of the strip as if it was an individual line request. Possibly every GL implementation is flawed this way, which is not a great prospect to getting that ever fixed.
So the idea was to have glamor convert X11 line drawing requests not to GL lines, but to a GL polygon that looks like a line. That way, the joints would at least look right. To combat the rounding issue, that polygon would also have to extend 0.5 pixels outwards.