Which is the best/correct way to get an hardware accelerated canvas suitable for both java2d and java2d-ogl-accelerated ?
Mik
Which is the best/correct way to get an hardware accelerated canvas suitable for both java2d and java2d-ogl-accelerated ?
Mik
Um… Could you please clarify. What do you mean under ‘accelerated canvas’?
I mean a canvas where translucent blitting is hardware accelerated. Sorry but I have some confusion in my mind about this topic.
I tried to open a JFrame and issue a bunch of drawImage() of managed translucent images, but I didn’t get any acceleration (I checked the blit loops in the gfx debug dump).
Take a look at my silly java2d benchmark here:
http://www.classx.it/public/j2dbenchmark.jar
Mik
I dont ‘get’ that benchmark - it reports around 125 for every operation when drawing to the JFrame with SRC_OVER.
That’s right. Your machine is doing 125/s drawImage() SRC_OVER of 250x250 bitmap.
Mine gives ~ 365 offscreen and ~216 inside the jframe.
Did you notice that the performance falls to 10 ops/s when using -Dsun.java2d.opengl=True and blitting inside the jframe ?
Mik
It is reporting 125 for every operation though.
Regardless of whether it is a int [] ARGB, int ARGB, ManagedImage, fullAlphaManagedImage, drawString, etc etc etc.
In my own tests, I can blit a 250x250 managed image alot more than 125 times/second.
Just a quick translation using numbers I get from Balls.jar
With that, I get 5000blits 32x32@30fps.
A simplistic comparison would be 500030 3232 / (250250) ~= 2500
However this is ignoring the extra overhead of the drawImage calls, the bouncing of the balls, and numerous other things.
So I would expect a number even higher than this - 5000 to 10000 blits/second perhaps even higher.
Something is not ‘right’ with your benchmark (or im misunderstanding what exactly you are benchmarking)
I would knock together a comparable blit test…
but i don’t think it’d give very useful results at the moment, as im encoding an xvid =)
[quote] Something is not ‘right’ with your benchmark (or im misunderstanding what exactly you are benchmarking)
[/quote]
Why don’t you take the source code and give it a look ?
The runner loop looks like this:
public void run()
{
long time = System.currentTimeMillis();
int cnt = 0;
int dm=0,sm=0,cmp=0;
Composite composite = CmpArray[cmp];
BufferedImage img = srcImg[sm];
Graphics2D g = dstGraphics[dm];
AffineTransform at = new AffineTransform();
// prepare test Frame
JFrame testFrame = new JFrame();
testFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
JPanel panel = new JPanel();
panel.setBackground(Color.blue);
testFrame.setTitle(testFrame+"");
testFrame.setLocation(10,10);
testFrame.setSize(WIDTH,HEIGHT);
testFrame.setContentPane(panel);
testFrame.setVisible(true);
dstGraphics[DST_ONSCREEN_FRAME] = (Graphics2D)panel.getGraphics();
while(true)
{
// each second
if ((System.currentTimeMillis()-time) >= 1000)
{
sm = getSrcMode();
dm = getDestMode();
img = srcImg[sm];
g = dstGraphics[dm];
// the composite
g.setComposite(CmpArray[getDestComposite()]);
// the transform flags
at.setToIdentity();
if (isRotate()) at.rotate(.2,WIDTH/2,HEIGHT/2);
if (isShear()) at.shear(.01,.01);
if (isTranslate()) at.translate(.1,.1);
if (isScale()) at.scale(1.5,1.5);
g.setTransform(at);
// the graphics hints
g.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,isAntialiasing() ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF));
g.addRenderingHints(new RenderingHints(RenderingHints.KEY_INTERPOLATION,isInterpolation() ? RenderingHints.VALUE_INTERPOLATION_BILINEAR: RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR));
// check if we should stop
synchronized (lock) {if (shouldStop) {break;}}
// update counter
getJLabel_speed().setText(cnt+"");
cnt = 0;
// reset timer
time = System.currentTimeMillis();
}
// draw
g.drawImage(img,cnt%10-5,cnt%10-5,null);
cnt++;
}
// the runner goes to null, so we can immediately restart
runner = null;
// dispose
testFrame.setVisible(false);
testFrame = null;
}