Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4468154

Graphics.drawImage() is much slower under 1.4 than under 1.2

XMLWordPrintable

    • 2d
    • beta2
    • sparc
    • solaris_8

      In Sun Management Center, Graphics.paintImage() is being used, we first copy the screen to a image as double buffer, then when there is a request from awt for repaint, the image will be painted again.
      Under jdk1.2, the speed to paint the image is quick, but under jdk1.4, the paint speed is very slow.

      refer to /net/hotsauce.eng/guest/sunmc_jdk1.4/src/java/com/sun/symon/base/console/views/topology/CvTopologyViewPanel.java for the implementation of SunMC.

      Please compile and run the following codes under jdk1.2 and jdk1.4, you can find the refresh difference.

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

      public class Test {
          Image DoubleBuffer = null;
          public Test() {
              JFrame f = new JFrame();
      MyCom com = new MyCom();
      f.getContentPane().add(com);
      f.setSize(800, 500);
      f.setVisible(true);
      com.createDBBuffer();
          }
          
          public static void main(String[] args) {
              new Test();
      new Test();
          }
      }

      class MyCom extends JComponent {
          Image DoubleBuffer = null;
          
          public MyCom() {
              setUI(MyComUI.createUI(this));
          }

          public void createDBBuffer() {
              DoubleBuffer = createImage(500, 500);
      Graphics gr = DoubleBuffer.getGraphics();
      gr.setFont(getFont());
              gr.setColor(Color.blue);
              gr.fillRect(0, 0, 800, 500);
          }

          public void paintBuffer(Graphics gr) {
              if (DoubleBuffer != null) {
      gr.drawImage(DoubleBuffer, 0, 0, Color.black, null);
      }
          }
      }

      class MyComUI extends ComponentUI {
          MyCom com;
          
          public MyComUI(JComponent c) {
              com = (MyCom)c;
          }

          public void paint(Graphics g, JComponent c) {
              com.paintBuffer(g);
          }

          public Dimension getPreferredSize(JComponent c) {
              return new Dimension(800, 500);
          }

          public Dimension getMinimumSize(JComponent c) {
              return getPreferredSize(c);
          }

          public Dimension getMaximumSize(JComponent c) {
              return getPreferredSize(c);
          }

          public static ComponentUI createUI(JComponent c) {
              return new MyComUI(c);
          }
      }

            tdv Dmitri Trembovetski (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: