Which methods from Graphics2D are HW-accelerated?

Which methods from Graphics2D (got with createGraphics from a BufferedImage which was got with createCompatibleImage) are Hardwareaccelerated?
All of them or only drawImage(). And if only drawImage is accelerated, what happens if I call (e.g.) drawLine()?
Is the line drawn on the BufferedImage in the VRAM, or is the (BufferedImage in) VRAM copied to SystemRAM, the line drawn and the result copied back to VRAM?

And what happens if I call setRGB() from the BufferedImage?

And is there absolutely no HW acceleration for linux?

Simply put, none.

Managed images (those created with create/CompatibleImage) are cached in vram, but all the rendering goes to the surface in system memory (the ‘master’ copy), and, thus, is unaccelerated (rendering is performed by our software loops).

It’s different for VolatileImages: they don’t have a system memory copy, and the rendering happens to the surface in vram. Currently (as of 1.4.2) only a small number of rendering primitives is accelerated - drawlines, fillRects, etc (some through ddraw, some through GDI and some via d3d) and copying of other accelerated images to a VolatileImage (and, with a flag, alpla blending of translucent managed images, using d3d).

The stuff said above is valid for windows. On unix it’s different.
First, on unix opaque managed images don’t have a system memory copy, they are stored in Pixmaps, and all rendering is done to them using X11 (except for the stuff X11 can’t handle, of course). Whether this rendering is accelerated or not, and whether Pixmap is stored in vram, is driver/Xserver dependent.

1-bit transparent managed images, however, do have system memory copies, similar to the windows implementation, and rendering goes to the system memory copy.

There’s tons of other details, you can take a look at this (somewhat outdated) paper

http://java.sun.com/products/java-media/2D/perf_graphics.html

Basically, the idea is that one should use VolatileImage for images which are modified often (like a back-buffer), and use managed images for sprites and such.

hmmm… i guess you would be the one to ask… so if i’m just constantly updating an image and want to keep putting the newly-updated image on the screen, how do I work this? I would need to draw other images on the large image for each update, which would involve transparency, but the large image itself would end up totally opaque… so should I use a volatile image for the large one? and draw bufferedImages onto it or regular images or other volatile images? if I use awt to draw the large image to a window will that slow it down or am I supposed to use awt? sorry for not understanding this very well but i’ve just been using regular Image objects with a Frame window and suffering through bad performance, and think it’s time I improved my code. Just several lines of pseudocode would be really helpful, thanks. :slight_smile:

I don’t know if it’s correct, but this is the way I would do it (dirty pseucdocode):


class Screen extends Frame implements Runnable
{
BufferStrategy BufferStrat;
VolitaleImage ImgBig;
Grpahics2D GrfxOnBig;
BufferedImage ImgSmall[];

public Screen()
{
System.setProperty("sun.java2d.translaccel", "true");       // for accelerated translucent  transperency
ImgBig = getGraphicsConfiguration().createCompatibleVolatileImage(Width, Height, true);     // the true for HW acceleration
GrfxOnBig = ImgBig.createGraphics();
ImgSmall = new BufferedImage[NumberOfSmallImgages];
for(int i = NumberOfSmallImgages-1; i >= 0; i--)
     {
     ImgSmall[i] = getGraphicsConfiguration().createCompatibleImage(ImgWidth,ImgHeight,Transparency.TRANSLUCENT);
     }
}

public void run()
{
Graphics2D GrfxScreen;
createBufferStrategy(2);     // to get accelerated screensurfaces
BufferStrat = this.getBufferStrategy();
GrfxScreen = (Graphics2D)BufferStrat.getDrawGraphics();

while(ProgRuns == true)
for(int i = NumberOfSmallImgages-1; i >= 0; i--)
     {
     YourMethodToDrawOnSmallImg(SmallImg[i]);
     GrfxBig.drawImage(posX, posY, SmallImg[i];
     }
GrfxScreen.drawImage(posX, posY, BigImg);     // draw on backbuffer
BufferStrat.show();      // flipp back- and frontbuffer
}

}

and then


Screen MyScreen = new Screen();
new Thread(MyScreen).start();

This is like I approximately made it.
I hope I haven’t forgot some part you need.

The BufferedImage I just use because I haven’t found a way to make VolitaleImages with Alphachannels.

Someone else some hints?