« »

JDK6 Update10 Beta D3D problems – 15x slowdown fixed

Posted May 3rd, 2008 by

I’ve been using the JDK6 update 10 build 22 for a while now, and I love the AntiAliased text rendering using the native text rasterizer. However, there are still some issues to be worked out before this the native D3D pipeline is ready for primetime. For certain Java2D operations, the new D3D hardware accelerated pipeline is 15 times slower than the software pipeline! For more details, check out this thread on java.net. There is hope that this will be fixed in the next beta; I’m looking forward to it!

In the ScreamingToaster platform’s desktop application that I’m working on, I experienced a 1 second delay for some screens to render! To give you some perspective, it takes about 50-60 ms with the D3D pipeline turned off! That’s a pretty big slowdown. I wasn’t doing anything too complicated either. I was just copying a JComponent to an offscreen BufferedImage. I’m using Vista 64 with an NVidia 8600 card with 256 of VRAM.

Here’s the code that I was using to copy a JComponent to a compatible BufferedImage:

public static BufferedImage getImageOfComponent(JComponent comp, boolean opaque) {
  BufferedImage newImg = createCompatibleImage(comp.getWidth(), comp.getHeight(), opaque);
 
  Graphics2D g2 = g2.createGraphics();
  comp.paint(g2);
  g2.dispose();
 
  return newImg;
}
 
public static BufferedImage createCompatibleImage(int width, int height, boolean opaque) {
  GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
  GraphicsDevice d = e.getDefaultScreenDevice();
  GraphicsConfiguration c = d.getDefaultConfiguration();
  BufferedImage compatibleImage = c.createCompatibleImage(width,
                                                          height,
                                                          opaque
                                                              ? Transparency.OPAQUE
                                                              : Transparency.TRANSLUCENT);
  return compatibleImage;
}

Here’s the code I was using to capture the BufferedImages of 2 JComponents in order to perform some animation on these images:

// data

private float _phase = 0f;
 
private boolean _anim = false;
 
private SoftReference<BufferedImage> _imgCacheOld;
private SoftReference<BufferedImage> _imgCacheNew;
private Insets _insets;
 
// methods
 
public void init(JComponent container, JComponent oldSheet, JComponent newSheet) {
//  TimedSout out = new TimedSout();
 
//  out.sout("init with 2 sheets... start");
 
  GUIUtils.renderNow(container, oldSheet);
  GUIUtils.renderNow(container, newSheet);
 
//  out.sout("init with 2 sheets... rendering complete");
 
  _imgCacheOld = AppUtils.captureComponentToImage(
    true, oldSheet, TransitionEffect._blurOldSheet, _imgCacheOld);
//  out.sout("init with 2 sheets... copied 1st comp to image... this takes a LONG TIME");
 
  _imgCacheNew = AppUtils.captureComponentToImage(
    true, newSheet, TransitionEffect._blurNewSheet, _imgCacheNew);
//  out.sout("init with 2 sheets... copied 2st comp to image... this takes a LONG TIME");
 
  _insets = container.getInsets();
//  out.sout("init with 2 sheets... end");
 
}

For more information on this problem, check out this link on java.net discussion forums.

Update – May 11 2008 – Java 6 Update 10 BETA Build 23 fixes this slowdown! Download it here (Windows version). Read more about all the changes in Build 23 here.

 

Comments are closed.