[
https://issues.apache.org/jira/browse/PIVOT-633?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Greg Brown updated PIVOT-633:
-----------------------------
Fix Version/s: (was: 2.0)
I just ran some performance tests to see how the two approaches compare. My
test app drew a square 500,000 times using each approach. The results are
interesting. On my system:
- Scale: 1.0
- drawRect(): ~900ms
- drawRectangle2D(): ~300ms
- drawRectangle2D() (AA): ~2000ms
- Scale 2.0:
- drawRect(): ~1000ms
- drawRectangle2D(): ~600ms
- drawRectangle2D() (AA): ~3900ms
- Scale 4.0:
- drawRect(): ~1000ms
- drawRectangle2D(): ~900ms
- drawRectangle2D() (AA): ~4000ms
- Scale 8.0:
- drawRect(): ~1000ms
- drawRectangle2D(): ~1000ms
- drawRectangle2D() (AA): didn't test
- Scale 16.0:
- drawRect(): ~1300ms
- drawRectangle2D(): ~1400ms
- drawRectangle2D() (AA): didn't test
- Scale 32.0:
- drawRect(): ~1600ms
- drawRectangle2D(): ~1900ms
- drawRectangle2D() (AA): didn't test
Based on these numbers alone, it seems like GraphicsUtilities.drawRect() is not
a good optimization for the common case of scale 1.0. Using Rectangle2D in this
case is consistently faster.
However, I believe that the main reason this method was created was to avoid
some of the odd rounding behavior observed when using Rectangle2D without
applying anti-aliasing. Unfortunately, AA appears to significantly increase the
rendering time with Rectangle2D.
So, I'm not sure what the best solution is. Clearly, we don't want to use
Rectangle2D and blindly apply AA in every case. On the other hand, drawRect()
doesn't give us the best performance in the unscaled case.
For now, I will close this issue and leave it up to the skins to decide which
method is most appropriate. If we end up writing our own graphics API, we might
be able to simply perform this optimization in our own drawRectangle() method.
> Eliminate use of GraphicsUtilities.drawRect() and drawLine()
> ------------------------------------------------------------
>
> Key: PIVOT-633
> URL: https://issues.apache.org/jira/browse/PIVOT-633
> Project: Pivot
> Issue Type: Improvement
> Components: wtk
> Reporter: Greg Brown
> Priority: Minor
>
> These methods were originally created to provide better rendering behavior
> than the corresponding java.awt.Graphics#drawRect() and drawLine() classes.
> However, a better approach is to call Graphics2D#draw() with a Rectangle2D or
> a Line2D. This produces much better results when the display is scaled, since
> these primitives use true floating point values.
> A number of components including most buttons have already been updated to
> use the java.awt.geom classes, but many skins are still using
> GraphicsUtilities and should also be updated.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.