Hi Martin,

  Thanks a lot for the detailed report.

  There are two issues here:
    - some images loaded with Toolkit.getImage() (at least, pngs) aren't
      accelerated - this had been addressed in jdk7 but not in 6uN.
      I'll file a bug on this one.
    - for some unaccelerated images rendering performance degraded
      I'll see what can be done for this one.

  A workaround is, as you have mentioned, to use ImageIO for reading
  images.

  In Java 6u4:
3.861277 ms
6.203313 ms
7.477602 ms
2.312025 ms
2.202579 ms

  With 6uN without the fix I get:
48.689088 ms
40.162102 ms
47.807305 ms
49.540503 ms

  With the fix or the ImageIO work around:
0.094893 ms
0.0937 ms
0.119034 ms
0.09319 ms
0.092727 ms

  Thanks,
    Dmitri
  Java2D Team


[EMAIL PROTECTED] wrote:
Hello,

I see a noticeable performance degradation in one of my apps.
Painting PNG images (upscaling using bilinear or bicubic filtering) seems to be 
slower (factor of 20 in my case).
Loading the image using ImageIO instead of Toolkit#getImage seems to resolve 
the problem.

Test:

[code]
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;

public class PerformanceTest
{
    public static void main(String[] args)
    {
        EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                try
                {
                    initGUI();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        });
    }


    private static void initGUI() throws IOException, InterruptedException
    {
        JFrame frame = new JFrame();
        final ImagePanel imagePanel = new ImagePanel();
        frame.getContentPane().add(imagePanel, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setBounds(100, 100, 600, 600);
        frame.setVisible(true);

        Timer timer = new Timer(20, new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                imagePanel.repaint();
            }
        });

        timer.start();
    }


    private static class ImagePanel extends JPanel
    {
        private Image image;


        private ImagePanel() throws InterruptedException, IOException
        {
            image = Toolkit.getDefaultToolkit().getImage(new 
URL("http://java.sun.com/docs/books/tutorial/figures/uiswing/components/HtmlButtonMetal.png";));
            //image = ImageIO.read(new 
URL("http://java.sun.com/docs/books/tutorial/figures/uiswing/components/HtmlButtonMetal.png";));

            MediaTracker mediaTracker = new MediaTracker(this);
            mediaTracker.addImage(image, 1);
            mediaTracker.waitForAll();
        }


        protected void paintComponent(Graphics g)
        {
            long ns1 = System.nanoTime();
            int o = (int) (Math.random() * 20);
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 
RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2d.drawImage(image, o, o, 200, 200, null);
            long ns2 = System.nanoTime();
            System.out.println((ns2 - ns1) / 1000000. + " ms");
        }
    }
}
[/code]

Operating System is Windows Vista

Output:
1.6.0_05-ea-b04

[I] CheckAdaptersInfo
[I] ------------------
[I] Adapter Ordinal  : 0
[I] Description      : NVIDIA GeForce Go 7900 GS (Microsoft Corporation - WDDM)
[I] GDI Name, Driver : \\.\DISPLAY1, nvd3dum
[I] Vendor Id        : 0x10de
[I] Version          : 7.15.10.9746
[I] ------------------
[I] InitD3D: successfully created Direct3D9 object
[I] D3DGD_getDeviceCapsNative
[I] D3DPPLM::CheckDeviceCaps: device 0: Passed
[I] D3DContext::InitContext device 0
[I] D3DContext::ConfigureContext device 0
[I] D3DContext::ConfigureContext: successfully created device: 0
[I] D3DContext::InitDevice: device 0
[I] D3DContext::InitDefice: successfully initialized device 0
[V]   | CAPS_DEVICE_OK
[V]   | CAPS_ALPHA_RT_PLAIN
[V]   | CAPS_ALPHA_RTT
[V]   | CAPS_OPAQUE_RTT
[V]   | CAPS_LCD_SHADER | CAPS_BIOP_SHADER
[V]   | CAPS_MULTITEXTURE
[V]   | CAPS_TEXNONPOW2
[V]   | CAPS_TEXNONSQUARE
78.177883 ms
63.440185 ms
50.098336 ms
55.525353 ms
46.665708 ms
45.636387 ms
42.916208 ms
45.019688 ms
62.719773 ms
48.997568 ms
...

1.6.0_02-b05
[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 Go 7900 GS (Microsoft 
Corporation - WDDM)
6.752813 ms
2.110464 ms
2.243441 ms
2.47741 ms
3.281492 ms
2.323549 ms
2.153067 ms
2.332698 ms
2.236387 ms
...

Martin
[Message sent by forum member 'til77' (til77)]

http://forums.java.net/jive/thread.jspa?messageID=239186

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to