drawImage performance weirdness - [EDIT: small images]

My computer is capable of rendering a certain 800x600 image to the screen approximately 650 times per second. Now, if I render an image of size 253x253 I get framerates of 4300(!), which is reasonably close to the same time per pixel. But if I resize that Image to 252x252, the framerate drops to about 250, then increases to about 400 in about 20 seconds. Apparently only images that are sufficiently large are accelerated. Does anyone know what is going on here?

Images created with GraphicsConfiguration.createCompatibleImage(int,int,int). No pipeline is enabled. No FSEM mode. Rendering done on Canvas with bufferStrategy(2).

Using: Linux, 1200 MHz AMD Duron, GeForce440MX, JRE 1.5.0_b05.

Feel free to ask for further information if it may shed light on something. Sorry about the heavy editing of this post if you just viewed it, but I thought I might as well update it completely based on recent results.

EDIT: Clarification - when I said “resize” above, I meant selecting another size at compile-time.

I have found a workaround.

The following method


drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer) 

of java.awt.Graphics is able to draw parts of images. Rendering a “small” part of a “large” image will still be fast, as long as no rescaling is done (in which case rendering would probably still be fast).

Which type of image? Transparent, translucent or opaque?

Dmitri
Java2D Team

The image is opaque.

I tried to reproduce the problem in windows, without success. Nothing seems to happen with the framerate when I render small images. On the other hand, I get a maximum framerate of 1300 in windows, where in linux I can sometimes obtain more than 4000 fps. I guess I’ll have to experiment a bit more with this.

Note that unless you do Toolkit.getDefaultToolkit.sync() after you
rendered the images (at the end of each frame, for example) you’re measuring the speed at
which we can issue X11 calls, which is not what you want to measure.

X11 just queues those requests and does nothing. The sync() makes it
to flush the queue and process the requests - that is, to actually render the images.

Dmitri
Java2D Team

Okay, sync() didn’t seem to make any difference. Am I doing something wrong? Anyway, under windows the problem is not present, but the performance is not very high either. In linux, the performance is very good, but when the images are smaller than that value, performance drops tremendously.

I tried to run a tile-based game under windows and linux, and the performance on linux was extremely low, around 10 fps when it should easily output several hundred. As mentiond above I could increase performance by simply rendering parts of images, but this makes for highly ugly code. I just wonder whether the huge performance difference when rendering small images is because of the driver or Java2D.

Thanks for the help anyway.