Thursday, August 21, 2008

Programming, Debugging and Performance questions

Q: What's the difference between Graphics and Graphics2D?

A: The Graphics class has been around since the first release of Java and supports the more basic rendering operations which are sufficient for many applications. Graphics2D is a subclass of Graphics and adds all the Java 2D API features first introduced in Java 2 in 1998.

Q: Is there a list of the various runtime flags that Java2D uses?

A: Yes! Check out: http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html

Q: What kinds of graphics hardware acceleration does Java2D use?

A: This question has many answers, which depend on things like:
What release you are running (we are constantly improving our hardware acceleration renderers, so each release has more to offer)
What OS you are running (our story on Windows is different from our story on Linux which is again different from our story on Solaris ... and the Apple folks have their own story for their platform)

What kind of hardware you have (your graphics card capabilities can be the single most important factor in enabling Java2D hardware acceleration).

We have tried to write down some of the more interesting and important hardware acceleration features in various articles and blogs. Here are some pointers, but I'm sure you can find more:
OpenGL: Here is an article about our OpenGL support in J2SE 5.0: http://today.java.net/pub/a/today/2004/11/12/graphics2d.html
VolatileImage: here are two blogs about VolatileImage objects: http://weblogs.java.net/blog/chet/archive/2003/09/volatileimage_n.html and http://weblogs.java.net/blog/chet/archive/2003/09/volatileimage_q.html.
Windows/Direct3D: Here is a blog about some of the hardware acceleration improvements in Windows in the Java SE 6 release: http://weblogs.java.net/blog/chet/archive/2005/05/graphics_accele.html.

Q: How can I get better performance for my Java2D application?

A: The answer depends entirely on what you are trying to do, and what environment you are running on. There are a lot of articles you can read to see if they help you, such as:

All of the articles listed for the "hardware acceleration" Q&A above
An article on using Intermediate Images to accelerate repeated renderings of complex operations: http://java.sun.com/developer/technicalArticles/Media/intimages.

Online chat transcripts and interviews on performance:

http://java.sun.com/developer/community/chat/JavaLive/2005/jl0215.html and http://www.javahispano.org/text.viewer.action?file=chet_en.
The gamers on http://javagaming.org are highly sensitive to performance and that web site has several good discussions about performance issues.

Q: Are there any tracing facilities in Java2D to help me track down performance issues in my application?

A: Yes. In J2SE 1.4 and above, Sun's implementation of the Java2D API includes a simple system property that can help you determine the source of your performance bottleneck. Simply run your application with the following system property:

-Dsun.java2d.trace=[log[,timestamp]],[count],[out:],[help],[verbose]
For more information on this tracing facility, refer to the following documentation:
http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html#trace

0 comments: