Open hrj opened 9 years ago
Note that:
The corners need to dove-tail into each other. Especially noticeable when the colors of each side are different.
Aside, There is an interesting article on the web about low performance in Java with stroked graphics (can't find the link now), and I played with the benchmark a bit.
The result was (after warmup):
Test | Time (microseconds) |
---|---|
1. stroked | 52213.7 |
2. stroked (with overhang outside of clip bounds) | 151627.5 |
3. hard-coded dashes in a loop | 14884.0 |
4. simple line (for reference) | 454.2 |
Since in our use-case, we don't need to worry about overhanging strokes, the relevant comparison is in between 1
and 3
, that is about 3.5x difference.
However, there is a catch. The current code draws the dashes in a loop across the thickness of the border. This to get the nice dove-tail effect at the corners. The same effect could be achieved with a single stroked line, with a trapezoidal clip. The trapezoidal clipping might introduce an overhead (not measured yet).
If the thickness of the border is greater than 3.5 pixels, it will be faster to use the stroked line, and for smaller pixel thickness, the current algorithm is faster. (Assuming no overhead for trapezoidal clip)
Further to that, if adjoining borders have the same style, color, thickness, etc, then they could be drawn with a single path drawing operation. Especially when all four sides are the same, then a draw rectangle call can be used. This case will be common and hence worth optimising for.
GUITasks.drawDashed()
draws each dash individually!Using strokes from Graphics2D would be much more optimal.