Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

VolatileImage slower than BufferedImage?

843807Aug 9 2004 — edited Aug 9 2004
I'm working on a FreeSoftware project, Vexi ( http://www.vexi.org ), which is a remote GUI platform.

For the Java version (we use GCJ to generate native binaries for Win32, Linux, MacOS X, and Solaris) we're using a BufferedImage to manipulate off-screen frames and then rendering said BI to the screen. In essence, a classic double buffer which is written to and rendered frequently.

Everything I read indicates that using a VolatileImage instead of a BufferedImage should be (worst case) as fast or (best case) much, much faster. Yet, if I switch to using a VI, it actually has a significantly negative impact on performance compared to using the BI.

2 of us tried to slot in a VI instead of the BI. Evidently the process is not as simple as a 1v1 swap (with the obvious extra code to make one work in place of the other).

Here is the normal, BI-based jar:
http://darcs.vexi.org/charlie/vexi-20040809.jar

Here is a VI-based jar:
http://darcs.vexi.org/charlie/vexi-20040809-VolatileImage.jar

Test on the following:
http://darcs.vexi.org/charlie/demo-20040809.vexi

(To invoke: java -jar <.jar> <.vexi>)

The file that matters is:
http://darcs.vexi.org/charlie/core/src/org/ibex/plat/Java2.java

And the VI-patched version:
http://darcs.vexi.org/charlie/Java2-VolatileImage.java

Is there any advice out there on what particular issues might slow down VIs? Is any part of the API that should not be used when wishing to preserve performance? From looking at Java2.java, is there any advice on how to implement using a VI instead of the BI?

I accidentally deleted my patches, but here was our other developers attempt (probably better than my attempt anyhow), and bear in mind that both our attempts suffered from the same performance decrease:

hunk ./src/org/ibex/graphics/Surface.java 355
- PixelBuffer backbuffer = Platform.createPixelBuffer(Platform.getScreenWidth(), Platform.getScreenHeight(), this);
+ protected final PixelBuffer backbuffer = Platform.createPixelBuffer(Platform.getScreenWidth(), Platform.getScreenHeight(), this);
hunk ./src/org/ibex/plat/AWT.java 59
- protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h); }
+ protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new AWTPixelBuffer(w, h, (AWTSurface) owner); }
hunk ./src/org/ibex/plat/AWT.java 232
- static Component component = null;
+ protected static Component component = null;
hunk ./src/org/ibex/plat/AWT.java 235
- public AWTPixelBuffer(int w, int h) {
+ public AWTPixelBuffer(int w, int h, AWTSurface s) {
hunk ./src/org/ibex/plat/AWT.java 243
+
hunk ./src/org/ibex/plat/Java2.java 25
+import java.awt.image.VolatileImage;
hunk ./src/org/ibex/plat/Java2.java 40
- private boolean isJava14 = false;
+ private final static boolean isJava14;
hunk ./src/org/ibex/plat/Java2.java 42
- public Java2() {
- // disable the focus manager so we can intercept the tab key
+ static {
hunk ./src/org/ibex/plat/Java2.java 47
- if (version >= 1.4) {
- isJava14 = true;
+ isJava14 = version >= 1.4;
+ }
+
+ public Java2() {
+ // disable the focus manager so we can intercept the tab key
+ if (isJava14) {
+
hunk ./src/org/ibex/plat/Java2.java 111
- protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new Java2PixelBuffer(w, h); }
+ protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new Java2PixelBuffer(w, h, (Java2Surface) owner); }
hunk ./src/org/ibex/plat/Java2.java 192
+
+ public synchronized void render() {
+ AWTPixelBuffer pb = (AWTPixelBuffer) backbuffer;
+ if(!(pb.i instanceof VolatileImage)) throw new Error("should never happen");
+ VolatileImage vi = (VolatileImage) pb.i;
+ for(;;) {
+ super.render();
+ if(!vi.contentsLost()) break;
+ dirty(0,0,vi.getWidth(),vi.getHeight());
+ Log.debug(this,"Contents lost!");
+ }
+ }
hunk ./src/org/ibex/plat/Java2.java 232
- public Java2PixelBuffer(int w, int h) {
+ public Java2PixelBuffer(int w, int h, Java2Surface s) {
+ super(w,h,s);
hunk ./src/org/ibex/plat/Java2.java 271
- i = new BufferedImage(cm, raster, false, emptyHashtable);
+ if(isJava14) {
+ try {
+ Method m = Component.class.getMethod("createVolatileImage",new Class[]{Integer.TYPE, Integer.TYPE});
+ i = (java.awt.image.VolatileImage) m.invoke(component,new Object[]{new Integer(w),new Integer(h)});
+ } catch(Exception e) {
+ Log.error(this,"Exception while creating volatile image");
+ Log.error(this,e);
+ throw new UnsatisfiedLinkError();
+ }
+ } else {
+ i = new BufferedImage(cm, raster, false, emptyHashtable);
+ }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 6 2004
Added on Aug 9 2004
1 comment
229 views