No acceleration and wierd results, what am i doing wrong?

I have now made a couple of games using java2d and they work pretty well. However i was wondering why simply filling rectangles with a color took extremely long time to do, so i made a quick test. In this test i found that my images were never accelerated and getAvailableAcceleratedMemory() on GraphicsDevice always returned 0. I tested this on two machines, one running Windows Vista sp 1 and another running Windows Xp sp 2.

I did a couple of more tests to be sure. And i came up with this test case:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Tester extends JFrame{
	protected Image img;
	public Tester(){
		Canvas c = new Canvas(){
			public void paint(Graphics g){
				g.drawImage(img,0,0,this);
			}
		};
		
		c.setSize(512,512);
		add(c);
	
		System.out.println("test!");
		setResizable(false);
		validate();
		pack();
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setVisible(true);
		setLocationRelativeTo(null);
		
		img = createVolatileImage(512,512);//createImage(512,512);
		Graphics gra = img.getGraphics();
		gra.setColor(Color.BLUE);
		gra.drawLine(0,0,512-1,512-1);
		gra.dispose();
		
		int delay = 1000;
		ActionListener taskPerformer = new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GraphicsConfiguration gc = getGraphicsConfiguration();
				System.out.println("img.isAccelerated(): "+img.getCapabilities(gc).isAccelerated());
				System.out.println("img.isTrueVolatile(): "+img.getCapabilities(gc).isTrueVolatile());
			}
		};
		new Timer(delay, taskPerformer).start();
	}
	public static void main(String[] args){
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run(){
				new Tester();
			}
		});
	}
}

When running with -Dsun.java2d.trace=count on my Windows Vista machine for a few seconds i get this result:

test!
img.isAccelerated(): false
img.isTrueVolatile(): false
img.isAccelerated(): false
img.isTrueVolatile(): false
img.isAccelerated(): false
img.isTrueVolatile(): false
2 calls to sun.java2d.windows.GDIBlitLoops::Blit(IntRgb, SrcNoEa, "GDI")
5 calls to sun.java2d.loops.FillRect::FillRect(AnyColor, SrcNoEa, AnyInt)
1 call to GDIFillRect
1 call to sun.java2d.loops.DrawLine::DrawLine(AnyColor, SrcNoEa, AnyInt)
9 total calls to 4 different primitives

When running with -Dsun.java2d.opengl=true aswell, i get a window with a blank white canvas in the middle.
The console output after a few seconds is however:

test!
img.isAccelerated(): true
img.isTrueVolatile(): true
img.isAccelerated(): true
img.isTrueVolatile(): true
6 calls to OGLFillRect
1 call to OGLDrawLine
2 calls to sun.java2d.opengl.OGLRTTSurfaceToSurfaceBlit::Blit("OpenGL Surface (r
ender-to-texture)", AnyAlpha, "OpenGL Surface")
9 total calls to 3 different primitives

Please help me understand these results…
You will probably need more info on my system, but i didn’t know what was needed or how to get this info, so please ask if more info would help :slight_smile:

  • Scarzzurs

Please run any java app on those systems with J2D_TRACE_LEVEL env. variable
set to 4:
set J2D_TRACE_LEVEL=4
java -jar SwingSet2.jar

And post the output.

Dmitri

Thanks for the quick answer.

After running he test you suggested, i got the following besides the output i already posted:

[W] GetFlagValues: DDraw/D3D is disabled on Windows Vista
[W] GetFlagValues: DDraw screen locking is disabled (W2K, XP+)
[I] InitDirectX
[V] CheckRegistry: Found Display Device 0: NVIDIA GeForce 8600M GT

Hope it helps. :slight_smile:

  • Scarzzurs

Indeed, in releases prior to 6u10 the hw acceleration is disabled on Vista.

Have you tried a beta of 6u10 (the latest build available from http://jdk6.dev.java.net)?

Dmitri

Hey trembovetski.

Thanks for the quick answer, i’m sorry i couldn’t respond just as fast :slight_smile:
Anyways, the new beta version of 6u10 works just great. Everything gets hardware accelerated.
I’ve experienced some problems though.

  1. During fullscreen mode my games act differently when using noddraw and with the pipeline on. The components aren’t layed out right when using bufferstrategy to be more precise.
  2. The game crashed once with the following message:

[quote]#

An unexpected error has been detected by Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x04d1b2bb, pid=6640, tid=7788

Java VM: Java HotSpot™ Client VM (11.0-b11 mixed mode, sharing windows-x86)

Problematic frame:

C [nvd3dum.dll+0x1db2bb]

An error report file with more information is saved as:

C:\Projects\ProjectMISC\hs_err_pid6640.log

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

[/quote]
From what i can gather form the message the problem lies with vista/my driver for my graphics card.

Anyways, it’s great to finally see some hardware acceleration. :slight_smile:

  • Scarzzurs

Thanks for the report. We have little time to address issues in 6u10 so I would appreciate
prompt response =)

  1. do you use undecorated frames when entering full-screen mode? If not, it is highly advisable
    to do so. There are known issues with Direct3D and decorated frames.

  2. Could you please send me the log file from the crash if you still have it (tdv at sun dot com).
    Do you remember what it was doing when it crashed? Like, entering/exiting full-screen,
    changing the display mode?

Thanks,
Dmitri
Java2D Team