IMO the helper strategy in skin.Utils will never give us the best possible performance.
In TextLayout I added very aggressive caching mechanism to allow incremental changes.
For example, if you keep the same text and font, you can change the wrap width and text alignment a lot faster (as the heavy work to produces glyphs and advances is cached).
In the helper we flip the text and font every time. That wipes our caches.
The way I think this should be done would be something like this
static double computeTextWidth(Text labeledText, double wrappingWidth) {
TextLayout layout = labeledText.getTextLayout(); //new API in Text, private or public...
layout.setWrappingWidth(0);
float width = layout.getBounds().width;
if (wrappingWidth < width) {
layout.setWrappingWidth(wrappingWidth);
width = layout.getBounds().width;
}
layout.setWrappingWidth(labeledText.getWrappingWidth());//restore
return width;
}
Not sure this code is 100% correct, but by re-using the internal TextLayout from Text we don't have to set the font and text (which preserve glyphs and advances).
In TextLayout I added very aggressive caching mechanism to allow incremental changes.
For example, if you keep the same text and font, you can change the wrap width and text alignment a lot faster (as the heavy work to produces glyphs and advances is cached).
In the helper we flip the text and font every time. That wipes our caches.
The way I think this should be done would be something like this
static double computeTextWidth(Text labeledText, double wrappingWidth) {
TextLayout layout = labeledText.getTextLayout(); //new API in Text, private or public...
layout.setWrappingWidth(0);
float width = layout.getBounds().width;
if (wrappingWidth < width) {
layout.setWrappingWidth(wrappingWidth);
width = layout.getBounds().width;
}
layout.setWrappingWidth(labeledText.getWrappingWidth());//restore
return width;
}
Not sure this code is 100% correct, but by re-using the internal TextLayout from Text we don't have to set the font and text (which preserve glyphs and advances).
- relates to
-
JDK-8120598 8.0-graphics-scrum-1778: up to 50% performance regression in Controls benchmarks
-
- Closed
-