Hi Jan,
On Nov 14, 2006, at 1:48 AM, Jan Bösenberg (INCORS GmbH) wrote:
Chris, thanks for the information.
Antialiasing is switched off, and the lines are one pixel wide and
horizontal. But my app is not running slow at all, and I was only
wondering why about 50% of the time was spent on line drawing.
Since drawing the text only seems to be an issue of drawing some
bitmaps, this probably explains why.
Ah, if antialiasing is disabled, and you're only rendering thin
lines, then you should be using g.drawLine() instead of g.draw(new
Line2D...). Not only will this help avoid unnecessary garbage
allocation, but it will also be faster because g.drawLine()
essentially maps directly onto accelerated line rendering routines.
It's the old principle of "tell us what you mean": g.drawLine() is
explicit, whereas g.draw(Line2D) requires us to jump through hoops
just to arrive at the same conclusion.
Regarding more performance improvements I was wondering if a new
interface Shape2 could help in some cases. The interface could look
like this:
public interface Shape2 extends Shape {
public Shape getTransformedInstance(AffineTransform at);
public Shape intersection(Shape s);
// maybe more methods
}
If a shape implemented Shape2, in the clip() and setClip() methods
of Graphics2D you would not have to create a GeneralPath to get the
transformed shape, which currently seems to happen for all shapes
except rectangles. Instead the shape would be responsible of
creating a transformed instance, which in case of a Trapezoid and a
identity/translate/scale transform this could be a translated
instance of Trapezoid. The contains()/intersects() methods of these
instances can be much, much faster that the methods of a
GeneralPath instance.
Jim could probably comment more on your idea, but typically we
recommend the "intermediate image" approach to developers, which is
essentially a way to cache a pre-rasterized shape as a bitmap. For
the same reason that you suspect text rendering to require less CPU
cycles, the intermediate image approach is basically turning outlines
and fills into bitmap images, which are often much faster to render
than if you were to re-rasterize a bunch of shapes upon each
repaint. This is especially beneficial if you're rendering a whole
bunch of lines (or shapes, or whatever) with constant location,
transformation, etc. It definitely can save a lot of CPU cycles, at
the cost of more memory. See Chet's article on the subject:
http://java.sun.com/developer/technicalArticles/Media/intimages/
Thanks,
Chris
If this really helps improving performance, introducing the
interface should not be too difficult and backward compatible.
Standard implementations of the methods can always use the good old
GeneralPath to create transformed intances and intersections, but
it would also be possible to have optimized implementations. And
shapes that do not implement Shape2 will be treated as before.
Not sure if this idea is really worth thinking about, but I had the
feeling that I needed to share it ;-)
Cheers
Jan
Chris Campbell schrieb:
Hi Jan,
On Nov 10, 2006, at 3:17 AM, Jan Bösenberg (INCORS GmbH) wrote:
In one application I do a lot of text rendering and some line
drawing.
Much to my surprise, my profiler says that the app spends much
more time
on line drawing than on the text rendering. OK, I am using ready
made
GlyphVectors for the text rendering, which should make text
rendering
quite fast, but I still would not expect the app to spend that
much time
on line drawing.
Complex (wide, antialiased, etc) line drawing can be quite time
consuming, and you're right that it's not exactly a fair
comparison. In the text case, we can convert glyphs into bitmaps
which are much faster to render than say, on-the-fly rasterized
wide lines.
One important thing to note is that I am using a non-rectangular
shape
for clipping when drawing lines (I am using a trapezoid shaped
GeneralPath). The rest is simply done by creating a Line2D object,
setting a BasicStroke (with CAP_BUTT and JOIN_BEVEL) and calling the
draw(Shape s) method on the Graphics object.
Any ideas where the time is spent? Is it the non-rectangular
clipping shape?
I assume you have antialiasing enabled? For things like
antialiasing, non-rectangular clip, wide BasicStroke... any of
these things can cause us to fall back on a different renderer, so
it's not just one thing that's causing the slowdown. The OpenGL-
based pipeline can accelerate things like antialiased rendering as
well as complex clipping, so that might help improve performance
in your case. Short of that, we'll just need to continue
improving performance of our rasterizing code.
Thanks,
Chris
Cheers
Jan
====================================================================
=======
To unsubscribe, send email to [EMAIL PROTECTED] and include
in the body
of the message "signoff JAVA2D-INTEREST". For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".
=====================================================================
======
To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff JAVA2D-INTEREST". For general help, send
email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".